Copy link to clipboard
Copied
Hi
I have a form that I need splitting into 2. At the moment all values of the form go into a database.
I am using hidden fields to carry the values entered from page 1 to page 2.
Page 1 has multiple checkboxes. I carry the values in a hidden field but I am having trouble inserting them into the database. Each checkbox value should go on a new row in the database.
When I process the form - nothing happens ![]()
This is my sql code:
foreach ($_POST['samples'] as $value) {
$sql = mysql_query("Insert into samples SET samples ='$value'......");
}
Value in the hidden field:
$samples= implode(", \n", $_POST['samples']);
Am I on the right track by using hidden fields?
It all works on 1 page - but I need help to make it work on 2 pages.
Hope someone can help
Thanks
Copy link to clipboard
Copied
I would use sessions, but I'll show you how to do it this way.
On page 1, you'll want to create a normal form and you won't need any special code really. You'll only have to change the action.
For instance:
<form id="myForm" name="myForm" method="post" action="page2.php">
<p>
<label for="information">Information: </label>
<input type="text" name="information" id="information" />
</p>
<p>
<input type="submit" name="submit" id="submit" value="Submit" />
</p>
</form>
For the form I've created, on page2.php, I would put this above the html tag:
<?php
$infor=$_POST['information'];
?>
Then I'd build a form on page 2 that would have more information that they can insert and I would add however many hidden fields are needed to cover everything from the previous page. So you'd end up with this:
<form id="form1" name="form1" method="post" action="">
<input type="hidden" name="information" id="hiddenField" />
<label for="more_info">More Info: </label>
<input type="text" name="more_info" id="more_info" />
</form>
Then I'd change the code on the hidden field and end up with this:
<form id="form1" name="form1" method="post" action="">
<input type="hidden" name="information" id="hiddenField" value="<?php echo $infor;?> />
<label for="more_info">More Info: </label>
<input type="text" name="more_info" id="more_info" />
</form>
And then insert the form into your database using server behaviors in Dreamweaver or however you would do it.
Hope that helps...
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more