Jump to content

creating and passing form array


corbeeresearch

Recommended Posts

I'm trying to do a multi-page registration form, which includes allowing the user to enter the name of their car(registered name, plate number, year manufactured, brand, model, then what club, then a couple of radio buttons with yes or no answer). If they have more than one car, they can click add a new car, then they will be able enter another car information.

 

So I was thinking of form array, but how do I create form arrays, then pass them to php using post?

sending values inside an array is possible...

 

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="carname[]" value="car name1" /><br />
<input type="text" name="carname[]" value="car name2" /><br />
<input type="submit" name="cars"  value="send" /> 
</form>

<?php

if(isset($_POST['cars']))
{
foreach($_POST['carname'] as $item)
	echo "$item <br />";

}

?>

 

You can write a javascript function which appends a new input control to the document, like "<input type="text" name="carname[] />" />"  when "add buton" is clicked...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.