pixeltrace Posted March 5, 2007 Share Posted March 5, 2007 guys, i need help on my form, i wanted to place an validation message beside my text area instead of displaying the error message on a separate page. currently my error message is being displayed on a separate page and what happens is when the error message appear, the user has to manually click back to the form and retype the entire form. how do i do this? this is the current code in my form and i wanted to have the validation message beside the name, email and contact of the personal information field form method="post" action="referral.php?id=4"> <table width="494" border="0" cellspacing="2" cellpadding="0"> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2" align="center" bgcolor="#e5e5e5" class="text7">Please make sure that correct information is supplied so we can get back to you. </td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2" bgcolor="#F7F7F7" class="text6">Your Personal Information </td> </tr> <tr> <td colspan="2" valign="top" class="text6"><img src="../images/main/spacer.gif" width="8" height="6" /></td> </tr> <tr> <td width="119" align="right" class="text6">name : </td> <td width="369"><span class="text6"> <input name="yname" type="text" class="field3" /> </span></td> </tr> <tr> <td align="right" class="text6">email : </td> <td><input name="yemail" type="text" class="field3" /></td> </tr> <tr> <td align="right" class="text6">contact number : </td> <td><input name="ycontact" type="text" class="field3" /></td> </tr> <tr> <td align="right" class="text6">type of scheme : </td> <td><select name="inquiry" class="field3"> <option value="Refer a Friend" selected="selected">--Refer a Friend--</option> <option value="Associate Program">--Associate Program--</option> </select></td> </tr> <tr> <td align="right" class="text6"> </td> <td> </td> </tr> <tr> <td colspan="2" bgcolor="#F7F7F7" class="text6">Your Candidate Information </td> </tr> <tr> <td colspan="2" valign="top" class="text6"><img src="../images/main/spacer.gif" width="8" height="6" /></td> </tr> <tr> <td width="119" align="right" class="text6">name : </td> <td><span class="text6"> <input name="cname" type="text" class="field3" /> </span></td> </tr> <tr> <td width="119" align="right" class="text6">email : </td> <td><input name="cemail" type="text" class="field3" /></td> </tr> <tr> <td width="119" align="right" class="text6">contact number : </td> <td><input name="ccontact" type="text" class="field3" /></td> </tr> <tr> <td width="119" align="right" valign="top" class="text6">profession/ skills : </td> <td><textarea name="cskills" cols="35" rows="5" class="field3"></textarea></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td colspan="2" bgcolor="#F7F7F7" class="text6">If you have additonal questions/ inquiries, please type it here </td> </tr> <tr> <td colspan="2" valign="top" class="text6"><img src="../images/main/spacer.gif" width="8" height="6" /></td> </tr> <tr> <td> </td> <td><textarea name="additonal" cols="35" rows="5" class="field3"></textarea></td> </tr> <tr> <td> </td> <td><input name="Submit" type="submit" class="button1" value="Submit" /> <input type="hidden" name="recipient" value="[email protected]" /> <input type="hidden" name="cc" value="[email protected]" /> </td> </tr> <tr> <td colspan="2"> </td> </tr> </table> </form> and this is the current code of my referralsend.php here i would like to happen here is the validation will just be done on the form page and referralsend.php will just need to send all the information. <?php $yname = $_POST['yname']; $yemail = $_POST['yemail']; $ycontact = $_POST['ycontact']; $inquiry = $_POST['inquiry']; $cname = $_POST['cname']; $cemail = $_POST['cemail']; $ccontact = $_POST['ccontact']; $cskills = $_POST['cskills']; $recipient = $_POST['recipient']; $cc = $_POST['cc']; echo "<CENTER>"; if (($yname == "") || ($yemail == "") || ($ycontact == "")) { echo '<br><br><span class="text7">Please complete the form. Thanks!</span><br>'; exit; } if(!email_is_valid($yemail)) { echo '<br><br><span class="text7"><br>Email Address Invalid.<br>Please use a valid Email Address</span><br>'; exit; } $Message = ""; $Message .= "An Email from: $yname\n"; $Message .= "Contact Number: $ycontact\n"; $Message .= "Email Address: $yemail\n"; $ip = getenv("REMOTE_ADDR"); $Message .="IP address:".$ip."\n"; $Message .= "\n\n"; $Message .= "Type of scheme: $inquiry\n"; $Message .= "Candidate name: $cname\n"; $Message .= "Candidate contact number: $ccontact\n"; $Message .= "Candidate email: $cemail\n"; $Message .= "Candidate skills: $cskills\n"; $Message .= "\n\n"; $Message .= "Additional Questions/Inquiries: $additional\n"; $Message .= "\n\n"; $Header = $email; $To = "$recipient, $cc"; $Subject = "JH Referral Scheme"; // mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported mail($To,$Subject,$Message,"From: $Header"); echo '<script language=javascript> alert("Your message has been sent!");top.location = "referral.php?id=3";</script>'; function email_is_valid ($email) { if(eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $email, $check)){ if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) ) { return TRUE; } // THIS WILL CATCH DNSs THAT ARE NOT MX. if(checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY")){ return TRUE; } } return FALSE; } ?> hope you could help me with this. thanks a lot! Link to comment https://forums.phpfreaks.com/topic/41200-solved-need-help-on-form-validation/ Share on other sites More sharing options...
mmarif4u Posted March 5, 2007 Share Posted March 5, 2007 Use this: if ($yname=='' or $yemail=='' or $yemail==) { error ('Some required fields are blank.\\n'. 'Please fill them in and try again.'); } Use the following code for error and then save it as validate.php and include it as include("include/validate.php"); at the top of ur php code. validate.php: <?php function error($msg) { ?> <script language="JavaScript"> <!-- alert("<?php echo ($msg) ?> "); history.back(); --> </script> <?php exit; } ?> I think this will help. Link to comment https://forums.phpfreaks.com/topic/41200-solved-need-help-on-form-validation/#findComment-199591 Share on other sites More sharing options...
pixeltrace Posted March 5, 2007 Author Share Posted March 5, 2007 hi its working now but i am getting an error when sending the complete and correct information this is the error message that i am getting from line 54 Fatal error: Call to undefined function: getmxrr() in c:\hosting\webhost4life\member\diorgrace\new\referral\referralsend.php on line 54 what does this mean? this is the current code that i have for this page <?php $yname = $_POST['yname']; $email = $_POST['email']; $ycontact = $_POST['ycontact']; $inquiry = $_POST['inquiry']; $cname = $_POST['cname']; $cemail = $_POST['cemail']; $ccontact = $_POST['ccontact']; $cskills = $_POST['cskills']; $recipient = $_POST['recipient']; $cc = $_POST['cc']; if (($yname == "") || ($email == "") || ($ycontact == "")) { echo '<script language=javascript> alert("Please complete the form!");history.back();</script>'; exit; } if(!email_is_valid($email)) { echo '<script language=javascript> alert("Please use a valid email address!");history.back();</script>'; exit; } $Message = ""; $Message .= "An Email from: $yname\n"; $Message .= "Contact Number: $ycontact\n"; $Message .= "Email Address: $email\n"; $ip = getenv("REMOTE_ADDR"); $Message .="IP address:".$ip."\n"; $Message .= "\n\n"; $Message .= "Type of scheme: $inquiry\n"; $Message .= "Candidate name: $cname\n"; $Message .= "Candidate contact number: $ccontact\n"; $Message .= "Candidate email: $cemail\n"; $Message .= "Candidate skills: $cskills\n"; $Message .= "\n\n"; $Message .= "Additional Questions/Inquiries: $additional\n"; $Message .= "\n\n"; $Header = $email; $To = "$recipient, $cc"; $Subject = "JH Referral Scheme"; // mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported mail($To,$Subject,$Message,"From: $Header"); echo '<script language=javascript> alert("Your message has been sent!");top.location = "referral.php?id=3";</script>'; function email_is_valid ($email) { if(eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $email, $check)){ if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) ) { return TRUE; } // THIS WILL CATCH DNSs THAT ARE NOT MX. if(checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY")){ return TRUE; } } return FALSE; } ?> hope you could help me with this. thanks! Link to comment https://forums.phpfreaks.com/topic/41200-solved-need-help-on-form-validation/#findComment-199600 Share on other sites More sharing options...
mmarif4u Posted March 5, 2007 Share Posted March 5, 2007 Use only this, u echo the script, dont echo it. Code: if ($yname=='' or $yemail=='' or $yemail==) { error ('Some required fields are blank.\\n'. 'Please fill them in and try again.'); } Other thing u did not include the validate.php. Include it like this: <?php include("include/validate.php"); An ur rest of code. Link to comment https://forums.phpfreaks.com/topic/41200-solved-need-help-on-form-validation/#findComment-199602 Share on other sites More sharing options...
pixeltrace Posted March 5, 2007 Author Share Posted March 5, 2007 hi, i tried using your codes but regardless whether i complete the form or not it always prompts the error message what's wrong with my code? need help. this is the current code that i have <?php $yname = $_POST['yname']; $email = $_POST['yemail']; $ycontact = $_POST['ycontact']; $inquiry = $_POST['inquiry']; $cname = $_POST['cname']; $cemail = $_POST['cemail']; $ccontact = $_POST['ccontact']; $cskills = $_POST['cskills']; $recipient = $_POST['recipient']; $cc = $_POST['cc']; if ($yname=='' or $yemail=='' or $yemail=='') { error ('Some required fields are blank.\\n'. 'Please fill them in and try again.'); } ?> <?php function error($msg) { ?> <script language="JavaScript"> <!-- alert("<?php echo ($msg) ?> "); history.back(); --> </script> <?php exit; } ?> <? $Message = ""; $Message .= "An Email from: $yname\n"; $Message .= "Contact Number: $ycontact\n"; $Message .= "Email Address: $yemail\n"; $ip = getenv("REMOTE_ADDR"); $Message .="IP address:".$ip."\n"; $Message .= "\n\n"; $Message .= "Type of scheme: $inquiry\n"; $Message .= "Candidate name: $cname\n"; $Message .= "Candidate contact number: $ccontact\n"; $Message .= "Candidate email: $cemail\n"; $Message .= "Candidate skills: $cskills\n"; $Message .= "\n\n"; $Message .= "Additional Questions/Inquiries: $additional\n"; $Message .= "\n\n"; $Header = $yemail; $To = "$recipient, $cc"; $Subject = "JH Referral Scheme"; // mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported mail($To,$Subject,$Message,"From: $Header"); echo '<script language=javascript> alert("Your message has been sent!");top.location = "referral.php?id=3";</script>'; function email_is_valid ($email) { if(eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $yemail, $check)){ if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) ) { return TRUE; } // THIS WILL CATCH DNSs THAT ARE NOT MX. if(checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY")){ return TRUE; } } return FALSE; } ?> thanks! Link to comment https://forums.phpfreaks.com/topic/41200-solved-need-help-on-form-validation/#findComment-199616 Share on other sites More sharing options...
mmarif4u Posted March 5, 2007 Share Posted March 5, 2007 Ok ur code will look this. Code: <?php include("include/validate.php"); $yname = $_POST['yname']; $email = $_POST['yemail']; $ycontact = $_POST['ycontact']; $inquiry = $_POST['inquiry']; $cname = $_POST['cname']; $cemail = $_POST['cemail']; $ccontact = $_POST['ccontact']; $cskills = $_POST['cskills']; $recipient = $_POST['recipient']; $cc = $_POST['cc']; if ($yname=='' or $yemail=='' or $yemail=='') { error ('Some required fields are blank.\\n'. 'Please fill them in and try again.'); } $Message = ""; $Message .= "An Email from: $yname\n"; $Message .= "Contact Number: $ycontact\n"; $Message .= "Email Address: $yemail\n"; $ip = getenv("REMOTE_ADDR"); $Message .="IP address:".$ip."\n"; $Message .= "\n\n"; $Message .= "Type of scheme: $inquiry\n"; $Message .= "Candidate name: $cname\n"; $Message .= "Candidate contact number: $ccontact\n"; $Message .= "Candidate email: $cemail\n"; $Message .= "Candidate skills: $cskills\n"; $Message .= "\n\n"; $Message .= "Additional Questions/Inquiries: $additional\n"; $Message .= "\n\n"; $Header = $yemail; $To = "$recipient, $cc"; $Subject = "JH Referral Scheme"; // mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported mail($To,$Subject,$Message,"From: $Header"); echo '<script language=javascript> alert("Your message has been sent!");top.location = "referral.php?id=3";</script>'; function email_is_valid ($email) { if(eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $yemail, $check)){ if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) ) { return TRUE; } // THIS WILL CATCH DNSs THAT ARE NOT MX. if(checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY")){ return TRUE; } } return FALSE; } ?> Now make a folder named 'include' in ur www directory, save the following code there as validate.php <?php function error($msg) { ?> <script language="JavaScript"> <!-- alert("<?php echo ($msg) ?> "); history.back(); --> </script> <?php exit; } ?> And then run ur page. Also make sure that ur include/validate.php is accessed by this script. I mean that give a validate directory here. include("foldername/validate.php"); Link to comment https://forums.phpfreaks.com/topic/41200-solved-need-help-on-form-validation/#findComment-199623 Share on other sites More sharing options...
pixeltrace Posted March 5, 2007 Author Share Posted March 5, 2007 hi i tried this but the error message keeps on popping regardless whether i complete the form or not this is my current code now <?php include 'validate.php'; $yname = $_POST['yname']; $email = $_POST['yemail']; $ycontact = $_POST['ycontact']; $inquiry = $_POST['inquiry']; $cname = $_POST['cname']; $cemail = $_POST['cemail']; $ccontact = $_POST['ccontact']; $cskills = $_POST['cskills']; $recipient = $_POST['recipient']; $cc = $_POST['cc']; if ($yname=='' or $yemail=='' or $yemail=='') { error ('Some required fields are blank.\\n'. 'Please fill them in and try again.'); } $Message = ""; $Message .= "An Email from: $yname\n"; $Message .= "Contact Number: $ycontact\n"; $Message .= "Email Address: $yemail\n"; $ip = getenv("REMOTE_ADDR"); $Message .="IP address:".$ip."\n"; $Message .= "\n\n"; $Message .= "Type of scheme: $inquiry\n"; $Message .= "Candidate name: $cname\n"; $Message .= "Candidate contact number: $ccontact\n"; $Message .= "Candidate email: $cemail\n"; $Message .= "Candidate skills: $cskills\n"; $Message .= "\n\n"; $Message .= "Additional Questions/Inquiries: $additional\n"; $Message .= "\n\n"; $Header = $yemail; $To = "$recipient, $cc"; $Subject = "JH Referral Scheme"; // mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported mail($To,$Subject,$Message,"From: $Header"); echo '<script language=javascript> alert("Your message has been sent!");top.location = "referral.php?id=3";</script>'; function email_is_valid ($email) { if(eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $yemail, $check)){ if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) ) { return TRUE; } // THIS WILL CATCH DNSs THAT ARE NOT MX. if(checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY")){ return TRUE; } } return FALSE; } ?> and this is what's inside validate.php <?php function error($msg) { ?> <script language="JavaScript"> <!-- alert("<?php echo ($msg) ?> "); history.back(); --> </script> <?php exit; } ?> did i make it right? Link to comment https://forums.phpfreaks.com/topic/41200-solved-need-help-on-form-validation/#findComment-199645 Share on other sites More sharing options...
mmarif4u Posted March 5, 2007 Share Posted March 5, 2007 hi i tried this but the error message keeps on popping regardless whether i complete the form or not this is my current code now <?php include 'validate.php'; $yname = $_POST['yname']; $email = $_POST['yemail']; $ycontact = $_POST['ycontact']; $inquiry = $_POST['inquiry']; $cname = $_POST['cname']; $cemail = $_POST['cemail']; $ccontact = $_POST['ccontact']; $cskills = $_POST['cskills']; $recipient = $_POST['recipient']; $cc = $_POST['cc']; if ($yname=='' or $yemail=='' or $yemail=='') { error ('Some required fields are blank.\\n'. 'Please fill them in and try again.'); } $Message = ""; $Message .= "An Email from: $yname\n"; $Message .= "Contact Number: $ycontact\n"; $Message .= "Email Address: $yemail\n"; $ip = getenv("REMOTE_ADDR"); $Message .="IP address:".$ip."\n"; $Message .= "\n\n"; $Message .= "Type of scheme: $inquiry\n"; $Message .= "Candidate name: $cname\n"; $Message .= "Candidate contact number: $ccontact\n"; $Message .= "Candidate email: $cemail\n"; $Message .= "Candidate skills: $cskills\n"; $Message .= "\n\n"; $Message .= "Additional Questions/Inquiries: $additional\n"; $Message .= "\n\n"; $Header = $yemail; $To = "$recipient, $cc"; $Subject = "JH Referral Scheme"; // mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported mail($To,$Subject,$Message,"From: $Header"); echo '<script language=javascript> alert("Your message has been sent!");top.location = "referral.php?id=3";</script>'; function email_is_valid ($email) { if(eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $yemail, $check)){ if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) ) { return TRUE; } // THIS WILL CATCH DNSs THAT ARE NOT MX. if(checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY")){ return TRUE; } } return FALSE; } ?> and this is what's inside validate.php <?php function error($msg) { ?> <script language="JavaScript"> <!-- alert("<?php echo ($msg) ?> "); history.back(); --> </script> <?php exit; } ?> did i make it right? If u save ur validate.php in the same folder where ur this page is, then ok But u forgot to use this () here: include("validate.php"); correct it. Link to comment https://forums.phpfreaks.com/topic/41200-solved-need-help-on-form-validation/#findComment-199648 Share on other sites More sharing options...
pixeltrace Posted March 5, 2007 Author Share Posted March 5, 2007 hi, i corrected it already but its still popping up the error message regardless whether the form is complete or not. this is the current code that i have now <?php include("validate.php"); $yname = $_POST['yname']; $email = $_POST['yemail']; $ycontact = $_POST['ycontact']; $inquiry = $_POST['inquiry']; $cname = $_POST['cname']; $cemail = $_POST['cemail']; $ccontact = $_POST['ccontact']; $cskills = $_POST['cskills']; $recipient = $_POST['recipient']; $cc = $_POST['cc']; if ($yname=='' or $yemail=='' or $yemail=='') { error ('Some required fields are blank.\\n'. 'Please fill them in and try again.'); } $Message = ""; $Message .= "An Email from: $yname\n"; $Message .= "Contact Number: $ycontact\n"; $Message .= "Email Address: $yemail\n"; $ip = getenv("REMOTE_ADDR"); $Message .="IP address:".$ip."\n"; $Message .= "\n\n"; $Message .= "Type of scheme: $inquiry\n"; $Message .= "Candidate name: $cname\n"; $Message .= "Candidate contact number: $ccontact\n"; $Message .= "Candidate email: $cemail\n"; $Message .= "Candidate skills: $cskills\n"; $Message .= "\n\n"; $Message .= "Additional Questions/Inquiries: $additional\n"; $Message .= "\n\n"; $Header = $yemail; $To = "$recipient, $cc"; $Subject = "JH Referral Scheme"; // mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported mail($To,$Subject,$Message,"From: $Header"); echo '<script language=javascript> alert("Your message has been sent!");top.location = "referral.php?id=3";</script>'; function email_is_valid ($email) { if(eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $yemail, $check)){ if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) ) { return TRUE; } // THIS WILL CATCH DNSs THAT ARE NOT MX. if(checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY")){ return TRUE; } } return FALSE; } ?> Link to comment https://forums.phpfreaks.com/topic/41200-solved-need-help-on-form-validation/#findComment-199653 Share on other sites More sharing options...
mmarif4u Posted March 5, 2007 Share Posted March 5, 2007 what is ur directory name. where r ur files saved in folders, show ur me ur paths... Link to comment https://forums.phpfreaks.com/topic/41200-solved-need-help-on-form-validation/#findComment-199655 Share on other sites More sharing options...
mmarif4u Posted March 5, 2007 Share Posted March 5, 2007 Sorry i put $yeamil twice in ur code Change like this: if ($yname=='' or $yemail=='' or $ycontact=='') { error ('Some required fields are blank.\\n'. 'Please fill them in and try again.'); } Link to comment https://forums.phpfreaks.com/topic/41200-solved-need-help-on-form-validation/#findComment-199657 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.