Jump to content
Killersites Forums

Form values into an indexed array


dms
 Share

Recommended Posts

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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...