dms Posted February 5, 2010 Report Share Posted February 5, 2010 I'm wanting to create a form with several rows to send out invitations. e.g. Name: "value" Email: "value" Name: "value" Email: "value" Name: "value" Email: "value" How would I code this to place the form values into an array? Would something like this work? <?php " ";?> Would simply placing brackets after the value variable, create an indexed array? e.g.... $whole_name[] Quote Link to comment Share on other sites More sharing options...
Michael_ Posted February 7, 2010 Report Share Posted February 7, 2010 close, just added brackets [] is used for checkboxes, because you have text fields you shoud include an index inside the brackets. //assuming you have a for loop like for ($row=0; $row<5; $row++) { echo "... name=\"whole_name[$row]\" ..."; } // fyi html also likes single quotes, this just looks cleaner echo "... name='whole_name[$row]' ..."; // it will return $_POST['whole_name'][0] Quote Link to comment Share on other sites More sharing options...
dms Posted February 8, 2010 Author Report Share Posted February 8, 2010 (edited) I do have a for loop, if it's correct. Thanks for the heads up using single quotes. Everything I've read has used double quotes for some reason. Don't I need double quotes, where there is a Variable or Array involved? Let me try again. <?php // to be used in the for-loop below. $invite_tr = " \" id='whole_name' /> \" id='email_list' /> "; // display the number of input rows for invites. for ( $c=0, $c<$n, $c++) { echo $invite_tr; } ?> Edited February 8, 2010 by dms Quote Link to comment Share on other sites More sharing options...
Michael_ Posted February 8, 2010 Report Share Posted February 8, 2010 No, you will just echo the same thing $n times. Take a look at this <?php // display the number of input rows for invites. for ( $c=0, $c<$n, $c++) { echo " \n"; } ?> View your html source to see the generated code. You will have name='whole_name[0]' Also, I removed id= because unless you're doing stuff with client side java script you don't need it, and if you do it must be a unique value (to be valid html) so you'd have to append $c to the id value Quote Link to comment Share on other sites More sharing options...
dms Posted February 8, 2010 Author Report Share Posted February 8, 2010 I removed id= because unless you're doing stuff with client side java script you don't need it No java script in use. I've been wondering about the "id" attribute. Thanks! Whether to use "id" or "name" has been confusing to me. Most books use "name", but one HTML book I've read suggest using "id" due to the "name" attribute being deprecated. Quote Link to comment 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.
Note: Your post will require moderator approval before it will be visible.