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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.