moise Posted January 21, 2007 Share Posted January 21, 2007 hello i am trying to build a contact form but i am having the following problem and wonder if anyone could help. i need to the contact form to able to show success or error message in a new page and verify if all fields have been filled, how do i do that please?[code]<?phpif(isset($_POST['submit'])) { $to = "[email protected], [email protected]"; $name_field = $_POST['name']; $email_field = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $body = "$message"; $continue = "/"; // will send me to my homepage [b]echo "Thanks $name_field, Your message has been submitted to $to!";<p><a href="<?php print $continue; ?>">Click here to continue</a></p>"[/b]// i need to display the lines above in a new pagemail($to, $subject, $body);} else {echo "OH NOOOO!";} ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body></body></html>[/code]i am getting the following error: [quote]Parse error: syntax error, unexpected $end in /home/.malcsi/moisea66/tyreese.upfrontec.com/mailer.php on line 39[/quote]many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/35029-contact-form-messages-in-new-page-how/ Share on other sites More sharing options...
Jessica Posted January 21, 2007 Share Posted January 21, 2007 You went from PHP to HTML without closing your PHP. Try this.[code]$continue = "/"; // will send me to my homepage echo "Thanks $name_field, Your message has been submitted to $to!";?><p><a href="<?php print $continue; ?>">Click here to continue</a></p><?mail($to, $subject, $body);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35029-contact-form-messages-in-new-page-how/#findComment-165214 Share on other sites More sharing options...
moise Posted January 21, 2007 Author Share Posted January 21, 2007 thanks jesirose it works, but how will i make the messages display on a new page message.php for exple. i also notice this form sends emails without any field being filled how would i make a stop on it. sorry might be dumb questions but i am new.i started a server sidec email verification function[code]// Function email address validation checking function isValidEmail($email){ $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"; if (eregi($pattern, $email)){ return true; } else { return false; } }[/code]but it seems that does not stop it from sending bank email .many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/35029-contact-form-messages-in-new-page-how/#findComment-165270 Share on other sites More sharing options...
moise Posted January 21, 2007 Author Share Posted January 21, 2007 i sorted [quote]how will i make the messages display on a new page message.php for exple.[/quote] but still have a problem of verification of fields. this is what i've got for the email verificaton, but doen't seem right because it keep telling me that my email address is invalid.here's the code[code]<?php// Function email address validation checking function isValidEmail($email){ $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"; if (eregi($pattern, $email)){ return true; } else { return false; } } if (isset($_POST['submit'])) { if (isValidEmail($_POST['email'])){ echo "The email: ".$_POST['email']." is valid! "; } else{ echo " The email: ".$_POST['email']." is invalid! "; } } ?>[/code]any idea how to verify an text field too?many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/35029-contact-form-messages-in-new-page-how/#findComment-165292 Share on other sites More sharing options...
mattd8752 Posted January 21, 2007 Share Posted January 21, 2007 isset($var) would work in an if command using && between each. This could also only check selected sections like email not being req'd Quote Link to comment https://forums.phpfreaks.com/topic/35029-contact-form-messages-in-new-page-how/#findComment-165297 Share on other sites More sharing options...
moise Posted January 21, 2007 Author Share Posted January 21, 2007 thanks matt, this is what i came up with:[code]<?phpif(isset($_POST['submit'])) { $to = "[email protected], [email protected]"; $subject = $_POST['subject']; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['message']; $body = "$message"; $continue = "/"; // homepage or "mypage.htm" or "http://www.elsewhere.com/page.htm" // email validation $error_msg=''; if(trim($name)==''{ $error_msg.="Please enter your Name and/or Surname !<br>"; } if(trim($subject)=='' { $error_msg.="Please enter a subject title !<br>"; } if(trim($email_input)=='') { $error_msg.="Please enter an email<br>"; } else { // check if email is a valid address in this format [email protected] if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $email_input)) $error_msg.="Please enter a valid email address<br>"; } // display error message if any, if not, proceed to other processing if($error_msg==''){ // other process here } else { echo "<font color=red>$error_msg</font>"; } } mail($to, $subject, $body);} else {echo "OH NOOOO!";} ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><div id="contact-message"><!--Thank you <b><?php $name_field ?></b><br>Your message has been sent to <b><?php $to ?></b><p><a href="<?php print $continue; ?>">Click here to continue</a></p> --><?phpecho "Thanks <b>$name_field</b>, Your message has been submitted to <b>$to</b>!";?><p><a href="<?php print $continue; ?>">Click here to continue</a></p></div></body></html>[/code]but i am getting this parse error:[quote]Parse error: syntax error, unexpected '{' in /home/.malcsi/myusername/myweb.com/mailer.php on line 16[/quote]when i deleted the "{" i get the following parse too.[quote]Parse error: syntax error, unexpected T_VARIABLE in /home/.malcsi/myusername/myweb.com/mailer.php on line 17[/quote]can someone help me fix this problem please?many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/35029-contact-form-messages-in-new-page-how/#findComment-165767 Share on other sites More sharing options...
Nhoj Posted January 21, 2007 Share Posted January 21, 2007 You're missing a closing ) in[code=php:0]if(trim($name)==''[/code]Make this part:[code=php:0]if(trim($name)=='') { $error_msg.="Please enter your Name and/or Surname !<br>";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35029-contact-form-messages-in-new-page-how/#findComment-165768 Share on other sites More sharing options...
moise Posted January 21, 2007 Author Share Posted January 21, 2007 thanks Nhoj but i am still getting the parse error : syntax error, unexpected T_STRING on line 17i have no clue on this... Quote Link to comment https://forums.phpfreaks.com/topic/35029-contact-form-messages-in-new-page-how/#findComment-165780 Share on other sites More sharing options...
Philip Posted January 21, 2007 Share Posted January 21, 2007 [code]<?phpif(isset($_POST['submit'])) { $to = "[email protected], [email protected]"; $subject = $_POST['subject']; $name_field = $_POST['name']; $email_field = $_POST['email']; $message = $_POST['message']; $body = "$message"; $continue = "/"; // homepage or "mypage.htm" or "http://www.elsewhere.com/page.htm" // email validation $error_msg=''; if(trim($name)=='') { $error_msg.="Please enter your Name and/or Surname !<br>"; } if(trim($subject)=='') { $error_msg.="Please enter a subject title !<br>"; } if(trim($email_input)=='') { $error_msg.="Please enter an email<br>"; } else { // check if email is a valid address in this format [email protected] if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $email_input)) { $error_msg.="Please enter a valid email address<br>"; } // display error message if any, if not, proceed to other processing if($error_msg==''){ // other process here } else { echo "<font color=red>$error_msg</font>"; } } mail($to, $subject, $body);} else { echo "OH NOOOO!";} ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><div id="contact-message"><!--Thank you <b><?php $name_field ?></b><br>Your message has been sent to <b><?php $to ?></b><p><a href="<?php print $continue; ?>">Click here to continue</a></p> --><?phpecho "Thanks <b>$name_field</b>, Your message has been submitted to <b>$to</b>!";?><p><a href="<?php print $continue; ?>">Click here to continue</a></p></div></body></html>[/code]You were missing 2 sets of ) (one was mentioned above) and you had a missing { on an if statement Quote Link to comment https://forums.phpfreaks.com/topic/35029-contact-form-messages-in-new-page-how/#findComment-165784 Share on other sites More sharing options...
moise Posted January 22, 2007 Author Share Posted January 22, 2007 thanks kingphilip, i did the changes before... the error was in here in fact.[code]} else { echo "OH NOOOO!";} [/code] i had to just delete it.but the bad new is it sends email, but i get the mailer.php page the following wierd message[quote]Please enter your Name and/or Surname !Please enter a subject title !Please enter an emailThanks , Your message has been submitted !Click here to continue[/quote]this happened, when i tried to both send a empty form and a form with just the email field filled, meaning doesn't check my form fields for validation. how did i managed that ??? ? ??? ?These are the php details of my form.[code]form action="mailer.php" method="post"><input type="text" name="name" value="<? echo $name; ?>" size="30" /><input type="text" name="email" value="<? echo $email; ?>" size="30" /><input type="text" name="subject" value="<? echo $subject; ?>" size="30" /><textarea name="message" cols="25" rows="4"></textarea><input type="submit" value="Send" name="submit" class="button" /><input type="reset" value="Reset" class="button" />[/code]many thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/35029-contact-form-messages-in-new-page-how/#findComment-165983 Share on other sites More sharing options...
moise Posted January 22, 2007 Author Share Posted January 22, 2007 hi, nearly there! :)the only error i am getting is, it does recognise my email. i am not getting the "please enter an email address" but i am getting "Please enter a valid email address" any ideas on how to solve this current problem please?i checked the mail validation and it seems correct to me.many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/35029-contact-form-messages-in-new-page-how/#findComment-166086 Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 You have:[code]$email_field = $_POST['email'];if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $email_input)) {[/code]The variables don't match, Quote Link to comment https://forums.phpfreaks.com/topic/35029-contact-form-messages-in-new-page-how/#findComment-166090 Share on other sites More sharing options...
moise Posted January 22, 2007 Author Share Posted January 22, 2007 oh thanks jesirose, just solved it :) Quote Link to comment https://forums.phpfreaks.com/topic/35029-contact-form-messages-in-new-page-how/#findComment-166092 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.