carlos1234 Posted November 14, 2009 Share Posted November 14, 2009 I just discovered today that I can apparently create arrays in my HTML forms but I have not seen official documentation on this anywhere and am wondering if this feature is a PHP capability (where PHP parses the HTML in the .php file and renders the array constructs into arrays) or whether the capability in question is a feature of just HTML (irrespective of what PHP does with it). Here is some code that shows what I am asking about... <?php if ($_SERVER['REQUEST_METHOD'] === 'POST') { echo "<pre>"; print_r($_POST); echo "</pre"; } ?> <form action="" method="POST"> <input type="submit" name="submit" value="Submit"> <br> <input type="text" name="field_set[1][sort]" value="1"> <input type="text" name="field_set[1][link_text]" value="About Me"> <input type="text" name="field_set[1][link_points_to]" value="about-me.txt"> <input type="text" name="field_set[2][sort]" value="2"> <input type="text" name="field_set[2][link_text]" value="Home"> <input type="text" name="field_set[2][link_points_to]" value="home.txt"> <input type="text" name="field_set[3][sort]" value="3"> <input type="text" name="field_set[3][link_text]" value="Privacy Policy"> <input type="text" name="field_set[3][link_points_to]" value="privacy-policy.txt"> </form> The output looks like this... Array ( [submit] => Submit [field_set] => Array ( [1] => Array ( [sort] => 1 [link_text] => About Me [link_points_to] => about-me.txt ) [2] => Array ( [sort] => 2 [link_text] => Home [link_points_to] => home.txt ) [3] => Array ( [sort] => 3 [link_text] => Privacy Policy [link_points_to] => privacy-policy.txt ) ) ) Anybody? Thanks. Carlos Quote Link to comment https://forums.phpfreaks.com/topic/181534-who-creates-form-arrays-html-or-php/ Share on other sites More sharing options...
rarebit Posted November 14, 2009 Share Posted November 14, 2009 Well, you've hard coded the form elements names in an array format (you could get php to generate it (it'd look the same as you have it)). Then when the data comes back to the server, it (not too sure here) passes the data to php which parses the data as an array (or the server parses the data and then passes it to the php engine) (either way server side). So, in reality php 'handles' the array, and the html is just html... Helped or not? Quote Link to comment https://forums.phpfreaks.com/topic/181534-who-creates-form-arrays-html-or-php/#findComment-957598 Share on other sites More sharing options...
carlos1234 Posted November 14, 2009 Author Share Posted November 14, 2009 Thanks rarebit but I am still unclear. I understand that the server receives stuff and then hands it over to the PHP interpreter for handling. In my case all files ending in .php. What I am unclear on is whether the array construct that you see in my HTML form is a capability of HTML itself or whether the array constructs in the form I posted only work because PHP reads the HTML and processes them as arrays? In other words does the HTML have an ability to return POST variables of an array kind irrespective of whether an HTML form is processed through PHP, Perl, or any other scripting language or is it a matter of a scripting language reading it as such but where HTML itself does not allow array constructs by itself. If I had the time I would see if the same thing could be possible with Perl but I haven't fooled with Perl in a long, long time. I hope my question makes sense. Carlos Quote Link to comment https://forums.phpfreaks.com/topic/181534-who-creates-form-arrays-html-or-php/#findComment-957617 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.