Jump to content

Recommended Posts

Posted

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[]

Posted

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]

Posted (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 by dms
Posted

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

Posted
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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...