Jump to content

[SOLVED] Making Form Fields Compulsory


RAH

Recommended Posts

Hi,

 

I need to make all of the fields on this form compulsory, not quite sure how to do so.  The code isn't finished yet, I just need to know what needs added to make all fields compulsory.

 

HTML:

 

<form action="send.php" method="post" enctype="multipart/form-data" target="_self">
													<div align="left">
														<table class="altcolumn" cellspacing=6 cellpadding=4 border=0 align="left">
															<tbody>
																<tr>
																	<td class="text" colspan="4" valign="top"><b>Please fill out the form below</b></td>
																</tr>
																<tr>
																	<td class="text" colspan="3" valign="top"><b>Full Name:<br>
																		</b><input size=32 name=name tabindex="1"></td>
																	<td class="text" valign="top"><b>Email Address:<br>
																		</b><input size=32 name=emailad tabindex="2"></td>
																</tr>
																<tr>
																	<td class="text" colspan="3" valign="top"><b>Home address:<br>
																		</b><input size=32 name=haddress tabindex="3"></td>
																	<td class="text" valign="top"><b>Date of arrival (DD/MM/YY):<br>
																		</b><input size=32 name=dateofa tabindex="4"></td>
																</tr>
																<tr>
																	<td class="text" colspan="3" valign="top"><b>Approximate time of arrival:<br>
																		</b><input size=32 name=time tabindex="5"></td>
																	<td class="text" valign="top"><b>Telephone No.:<br>
																		</b><input size=32 name=teleno tabindex="6"></td>
																</tr>
																<tr>
																	<td class="text" colspan="4" valign="top"><b>If you wish to add/remove items give details here:<br>
																		</b><span class="text"><textarea name=details rows="5" cols=55 tabindex="7"></textarea><br>
																		</span></td>
																</tr>
																<tr>
																	<td class="text" colspan="3" valign="top">
																		<table border="0" cellspacing="0" cellpadding="0">
																			<tr>
																				<td width="93">
																					<div align="left">
																						<input type=submit value=Submit name=Submit></div>
																				</td>
																				<td width="83"><input type="reset" border="0"></td>
																			</tr>
																		</table>
																	</td>
																	<td class="text" valign="top"></td>
																</tr>
															</tbody>
														</table>
													</div>
												</form>

 

 

 

 

PHP:

 

<body><?php

//--------------Send info to owner and confirmation to user ----------
// to address and subject (also \n is a return). (\t is a tab)

$toaddr = "info@site.com";
$subject = "Details from website : order";
$realname = $_POST['realname'];
$email = $_POST['email'];
$address = $_POST['address'];
$date = $_POST['dateofa];
$time = $_POST['time'];
$telno = $_POST['teleno'];
$details = $_POST['details'];


//mails webform to the website owner
mail("$toaddr", "$subject", "Details from website : order\n
\n
\n
Name : $realname\n
Email : $email\n
Holiday home address : $address\n
Date of arrival : $date\n
Approx time of arrival: $time\n
Mobile/Telephone No. : $telno\n
\n
Changes : $details\n
\n
\n",
"From: $email\r\n");

//-----------------------------------------------------------------------
//mail confirmation to user
// $confsubject is the subject the end user gets in their confirmation email

$confsubject = "test";
mail("$email", "$confsubject", "$realname\n

test

\n", "From: $toaddr\r\n");

//send user off to thank you page
$url = "http://www.site.com/confirm.html";
printf("<meta http-equiv=refresh content=\"0; url=$url\">"); 

?></body>

 

 

 

Thanks.

Link to comment
Share on other sites

in your php, after you assign each post var to a variable, check to make sure it is valid:

 

<?php

$validation = true; //assume its valid until proven otherwise below

$realname = $_POST['realname'];
if($realname == ""){
$validation = false;
$errMessage[] = "missing Real Name";
}

then at the end:

if(!$validation){
echo "form not valid";
//and some code to print out your errMessage array 
}else{
//if $validation is still true:
//here's your code to save the data and move on...
}
?>

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.