Chrisj Posted October 7, 2016 Share Posted October 7, 2016 This contact form code does not send the Form info, and does not show 'completed' or 'not completed' message, can you help me add what's needed, please? <form action="../index.php" method="post" name="contact_us" onSubmit="return capCheck(this);"> <tr> <td> <input id="name" name="name" value="NAME" onfocus="if (this.value=='NAME') {this.value=''; this.style.color='#000000';}" onclick="clickclear(this, 'Enter Name')" onblur="clickrecall(this,'Enter Name1')" /> </td> <td> <input id="name" name="email" value="EMAIL" onfocus="if (this.value=='EMAIL') {this.value=''; this.style.color='#000000';}" onclick="clickclear(this, 'Enter Email')" onblur="clickrecall(this,'Enter Email1')" /> </td> <td> <input id="name" name="subject" value="SUBJECT" onfocus="if (this.value=='SUBJECT') {this.value=''; this.style.color='#000000';}" onclick="clickclear(this, 'Enter Subject')" onblur="clickrecall(this,'Enter Subject1')" /> </td> </tr> <tr> <td colspan="3"><input id="textbox1" name="comments" value="COMMENTS" onfocus="if (this.value=='COMMENTS') {this.value=''; this.style.color='#000000';}" onclick="clickclear(this, 'Enter Comments')" onblur="clickrecall(this,'Enter Comments1')" /> </td> </tr> <tr> <td> <input id="captext" type="text" name="captext" style="maxlength="6" value="" /></td> <td><img src="../includes/captcha.php" border="0" id="verification_image" /></a><center><a onclick="refresh_security_image(); return false;" style="cursor:pointer;"><u>Refresh Image</u></a><center> </td> <td><input type="hidden" name="submitted" value="1" /><input class="my-input" type="submit" value="SEND MESSAGE"> </td> </tr> </form> <!--<script type="text/javascript"> if($_POST['submitted'] == "1"){ $your_email = "support@.....com"; $from = "From: contact-form@.....com". "\r\n"; $user_email = $_POST['email']; $user_name = $_POST['name']; $subject = $_POST['subject']; $email_body = $_POST['comments']; if($user_email == "" or $user_name == "" or $subject == "" or $email_body == ""){ $error = "Please Complete All Required* Fields"; }else{ $message = "ContactUs : \n \nUsers Email : $user_email \nUsers Name : $user_name \n\n\n Users Message : \n\n$email_body"; //SEND THE EMAIL - mail($your_email, $subject, $message, $from); $result = "Your Message Has Been Sent. Thank You"; } } $message = "ContactUs : \n \nUsers Email : $user_email \nUsers Name : $user_name \n\n\n Users Message : \n\n$email_body"; //End Contact Us - </script>--> Quote Link to comment https://forums.phpfreaks.com/topic/302293-help-with-contact-form-code/ Share on other sites More sharing options...
benanamen Posted October 7, 2016 Share Posted October 7, 2016 Umm, could it be your trying to run PHP as Javascript? Quote Link to comment https://forums.phpfreaks.com/topic/302293-help-with-contact-form-code/#findComment-1538110 Share on other sites More sharing options...
Chrisj Posted October 7, 2016 Author Share Posted October 7, 2016 Yes, sorry I got confused. So, I would need to put this in it's own php file? If so, how would the Form connect with that file, or visa versa Thanks if($_POST['submitted'] == "1"){ $your_email = "support@.....com"; $from = "From: contact-form@.....com". "\r\n"; $user_email = $_POST['email']; $user_name = $_POST['name']; $subject = $_POST['subject']; $email_body = $_POST['comments']; if($user_email == "" or $user_name == "" or $subject == "" or $email_body == ""){ $error = "Please Complete All Required* Fields"; }else{ $message = "ContactUs : \n \nUsers Email : $user_email \nUsers Name : $user_name \n\n\n Users Message : \n\n$email_body"; //SEND THE EMAIL - mail($your_email, $subject, $message, $from); $result = "Your Message Has Been Sent. Thank You"; } } $message = "ContactUs : \n \nUsers Email : $user_email \nUsers Name : $user_name \n\n\n Users Message : \n\n$email_body"; //End Contact Us - Quote Link to comment https://forums.phpfreaks.com/topic/302293-help-with-contact-form-code/#findComment-1538111 Share on other sites More sharing options...
benanamen Posted October 7, 2016 Share Posted October 7, 2016 <?php if ($_SERVER['REQUEST_METHOD'] == 'POST'){ // process form } ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <form action="<?= $_SERVER['SCRIPT_NAME'] ?>" method="post"> <!-- FORM HERE --> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/302293-help-with-contact-form-code/#findComment-1538113 Share on other sites More sharing options...
Chrisj Posted October 7, 2016 Author Share Posted October 7, 2016 Thank you for your reply. So, this part would come after // process form ? if($_POST['submitted'] == "1"){ $your_email = "support@.....com"; $from = "From: contact-form@.....com". "\r\n"; $user_email = $_POST['email']; $user_name = $_POST['name']; $subject = $_POST['subject']; $email_body = $_POST['comments']; if($user_email == "" or $user_name == "" or $subject == "" or $email_body == ""){ $error = "Please Complete All Required* Fields"; }else{ $message = "ContactUs : \n \nUsers Email : $user_email \nUsers Name : $user_name \n\n\n Users Message : \n\n$email_body"; //SEND THE EMAIL - mail($your_email, $subject, $message, $from); $result = "Your Message Has Been Sent. Thank You"; } } $message = "ContactUs : \n \nUsers Email : $user_email \nUsers Name : $user_name \n\n\n Users Message : \n\n$email_body"; //End Contact Us - Quote Link to comment https://forums.phpfreaks.com/topic/302293-help-with-contact-form-code/#findComment-1538114 Share on other sites More sharing options...
ginerjm Posted October 8, 2016 Share Posted October 8, 2016 Maybe you need to do a little reading to teach yourself something before embarking on a full-fledged project? Quote Link to comment https://forums.phpfreaks.com/topic/302293-help-with-contact-form-code/#findComment-1538119 Share on other sites More sharing options...
Destramic Posted October 9, 2016 Share Posted October 9, 2016 (edited) benanamen has shown you perfectly what to do: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST'){ // process form } ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <form action="<?= $_SERVER['SCRIPT_NAME'] ?>" method="post"> <!-- FORM HERE --> </form> </body> </html> try this <!DOCTYPE html> <html> <head> <title></title> </head> <body> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST'){ echo 'well done you have submitted the form'; } else { ?> <form action="<?= $_SERVER['SCRIPT_NAME'] ?>" method="post"> <input type="text" name="name" /> <input type="submit" name="submit" value="submit"/> </form> <?php } ?> </body> </html> Edited October 9, 2016 by Destramic Quote Link to comment https://forums.phpfreaks.com/topic/302293-help-with-contact-form-code/#findComment-1538144 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.