Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple HTML Forms with PHP

Status
Not open for further replies.

ChocolateLover

Programmer
Jan 5, 2006
12
0
0
GB
I've had a lot of help from this forum so I thought I'd try again:)

I have two forms on a page, both created using PHP.
This is the HTML for the first form, 'weeks':
Code:
<form action="booking.php" method="post" name="weeks">
<table width="650" cellspacing="0" cellpadding="5" border="0">
			<tr>
				<td>&bull; Sat 21 January 2006 (PM) - Sat 28 January 2006 (AM)</td>
				<td></td>
				<td>&pound; 550</td>
			</tr>
			<tr>
				<td>&bull; Sat 28 January 2006 (PM) - Sat 4 February 2006 (AM)</td>
				<td></td>
				<td>&pound; 475</td>
			</tr>
			<tr>
				<td>&bull; Pool &amp; Spa Heating Required at £100/week (&pound;200)? (Recommended in winter months)</td>
				<td>
					<select name="poolheatrequired" id="poolheatrequired" onChange="document.getElementById('weeks').submit();">
						<option value="No"selected >No</option>
						<option value="Yes">Yes</option>
					</select>
				</td>
				<td>£ 0</td>
			</tr>
			<tr>
				<td>&bull; <strong>TOTAL PRICE</strong></td>
				<td></td>
				<td><strong>&pound;1025</strong></td>
			</tr>
		</table>
	</form>

When the pull down list changes I use
Code:
onChange="document.getElementById('weeks').submit();"
to submit the page and recalculate some of the values (is there a better PHP way?). This works.

This is the HTML for the second form, 'booking_form':
Code:
		<form action="booking.php" method="post" name="booking_form">
		<table width="650" border="0" cellspacing="0" cellpadding="5" align="center">
			<tr>
				<td>* Title</td>
				<td colspan="2">
					<select name="title" id="title">
						<option>Mr</option>
						<option>Mrs</option>
						<option>Miss</option>
						<option>Ms</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>* Name</td>
				<td colspan="2"><input name="name" type="text" id="name" size="35"></td>
			</tr>
			<tr>
				<td>* Address</td>
				<td colspan="2"><textarea name="address" rows="4" id="address" cols="35"></textarea></td>
			</tr>
			<tr>
				<td>* Post/Zip Code</td>
				<td colspan="2"><input name="postcode" type="text" id="postcode"></td>
			</tr>
			<tr>
				<td>* Telephone</td>
				<td colspan="2"><input name="telephone" type="text" id="telephone"></td>
			</tr>
			<tr>
				<td>Mobile/Cell Phone</td>
				<td colspan="2"><input name="mobilephone" type="text" id="mobilephone"></td>
			</tr>
			<tr>
				<td>Email Address</td>
				<td colspan="2"><input name="email" type="text" id="email"></td>
			</tr>
 			<tr> 
				<td colspan="2">* I agree to the <strong><a href="terms.php" target="_blank">Terms and Conditions</a></strong> of booking</font></div></td>
				<td style="width:100px"><input type="checkbox" name="terms" value="Yes"> I agree</td>
			</tr>
			<tr>
				<td colspan="3">
					<br><br>
					<strong>Please list all the names in the party and ages of children under 18 (as required by Florida State Law) at the time of occupation.</strong>
				</td>
			</tr>
			<tr>
				<td></td>
				<td>Name</td>
				<td>Age<br>(if under 18)</td>
			</tr>
			<tr>
				<td>Name 1</td>
				<td><input name="name1" type="text" id="name1" size="40"></td>
				<td><input name="age1" type="text" id="age1" size="3"></td>
			</tr>
			<tr>
				<td>Name 2</td>
				<td><input name="name2" type="text" id="name2" size="40"></td>
				<td><input name="age2" type="text" id="age2" size="3"></td>
			</tr>

			<tr>
				<td>Any general queries, questions or enquiries</td>
				<td colspan="2"><textarea name="Questions" rows="6" id="address" cols="40">Enter any questions you may have here and we'll get back to you as soon as possible!</textarea></td>
			</tr>
			<tr>
				<td></td>
				<td colspan="2" valign="bottom">
					<br>
					<input name="Submit" type="image" value="Submit" src="graphics/buttons/payment.gif" onMouseOver="MM_swapImage('payment','','graphics/buttons/payment_over.gif',1)" onMouseOut="MM_swapImgRestore()" width="185" height="78" border="0" id="payment">
				</td>
			</tr>
		</table>
	</form>

I want to retain any data that the user has entered in 'booking_form' when the page is submitted, just in case they start to complete this form and then change the pulldown in the 'weeks' form, which would cause the page to be submitted.

When I use print_r($_POST) when the page is submitted, I only get an array for the first form 'weeks', nothing from the second 'booking_form', even though I have entered data to some of the fields.

If I delete the first form 'weeks' and submit, I do get an array for the second form, 'booking_form'.

Can anyone see what I'm doing wrong?

My next question is when I do get a $_POST array from the 'booking_form' form, what's the best way to retain the data?

Is it
if(isset($_POST['name']) {$name=$_POST['name'];}
if(isset($_POST['address']) {$address=$_POST['address'];}
etc and
<input name="name" type="text" id="name" size="35" value="<?php echo $name; ?>">
etc or is there a better why to loop through the array.

Any help is really appreciated.
 
to submit the page and recalculate some of the values (is there a better PHP way?).
Something has to submit the form so that the browser interacts with your script again.

My recommendation is to use only one form. But have that form have a varying number of fields depending on what the user has input.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top