RAH Posted September 7, 2007 Share Posted September 7, 2007 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 = "[email protected]"; $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 https://forums.phpfreaks.com/topic/68387-solved-making-form-fields-compulsory/ Share on other sites More sharing options...
micah1701 Posted September 7, 2007 Share Posted September 7, 2007 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 https://forums.phpfreaks.com/topic/68387-solved-making-form-fields-compulsory/#findComment-343817 Share on other sites More sharing options...
AdRock Posted September 7, 2007 Share Posted September 7, 2007 You could use for example $empty_fields_message = "<p>Please go back and complete all the fields in the form.</p>"; if(empty($username) && empty($password)) { echo $empty_feilds_message; } else { //do other code } Link to comment https://forums.phpfreaks.com/topic/68387-solved-making-form-fields-compulsory/#findComment-343907 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.