bondango Posted January 17, 2011 Share Posted January 17, 2011 need someone to look at some script (Form) that im working on, cant seem to get the data across to a PHP script. HTML :- Reset Submit which im trying to pass to this PHP script (contact.php) <?php ARRIVED AT PHP if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected])"; $email_subject = "web query"; $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "contact: ".clean_string($phone)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "postcode".clean_string($post)."\n"; $email_message .= "Vehicle: ".clean_string($vehicle)."\n"; $email_message .= "Reg: ".clean_string($reg)."\n"; $email_message .= "Other: ".clean_string($other)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> Thank you for contacting us. We will be in touch with you very soon. } ?> dont think im arriving at the PHP as the message i have inserted dosnt show. being looking at this for 2 hours now and my head hurts Ps when i het it working il be putting in captha (sp) Marty Link to comment Share on other sites More sharing options...
optim8 Posted January 17, 2011 Share Posted January 17, 2011 Evening. The message won't display as you written it inside the <?php tag. If you want it to display a message wrap it in an echo statement, e.g. echo("my message"); Also your querying the 'post' array when you submitted the form as a 'get'. Try method="post" rather than method="get". Cheers. Link to comment Share on other sites More sharing options...
bondango Posted January 17, 2011 Author Share Posted January 17, 2011 still nowt..will have a fresh look at it tomorrow Link to comment Share on other sites More sharing options...
SupraShaun Posted January 18, 2011 Share Posted January 18, 2011 As optim8 said, change your form method to post. But also you need to "return false" at the end of your form submit onclick, otherwise it will just follow the href (in this case just refresh the page). Here you go: Submit Is there any reason why you are using an "a" with an onclick rather than a "submit" input type? As should the form user have javascript disabled they wont be able to submit the form (which may not matter, depending on your audience). Also ARRIVED AT PHP isnt commented out, so change that to // ARRIVED AT PHP Link to comment Share on other sites More sharing options...
bondango Posted January 18, 2011 Author Share Posted January 18, 2011 As optim8 said, change your form method to post. But also you need to "return false" at the end of your form submit onclick, otherwise it will just follow the href (in this case just refresh the page). Here you go: Submit Is there any reason why you are using an "a" with an onclick rather than a "submit" input type? As should the form user have javascript disabled they wont be able to submit the form (which may not matter, depending on your audience). Also ARRIVED AT PHP isnt commented out, so change that to // ARRIVED AT PHP Well that seems to be passing it to the PHP script now. To be honest, this web malarky isnt my thing lol. I would like the information pushed to the contact.php page but not the user i.e. when they click submit the page refreshes but the information is still passed to the contact script Link to comment Share on other sites More sharing options...
SupraShaun Posted January 18, 2011 Share Posted January 18, 2011 Cool So is it working as you want now? Link to comment Share on other sites More sharing options...
bondango Posted January 18, 2011 Author Share Posted January 18, 2011 well on submitt the user gets a blank page (contact.php), i would have like the information to have been passed to the script but the user stays on the Form page if you get my meaning? Link to comment Share on other sites More sharing options...
SupraShaun Posted January 18, 2011 Share Posted January 18, 2011 I think I see what you mean. Require/ include contact.php (<?php require_once('contact.php');?>) above your form (as it wont run unless your form has been submitted anyway) and then change your form action to <?php print $_SERVER['REQUEST_URI']?>. Link to comment Share on other sites More sharing options...
optim8 Posted January 18, 2011 Share Posted January 18, 2011 Here's an example script from W3C Schools. Does what you want basically, just need to change the input fields. <?php if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "[email protected]", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; } else //if "email" is not filled out, display the form { echo " Email: Subject: Message: "; } ?> Link to comment Share on other sites More sharing options...
bondango Posted January 18, 2011 Author Share Posted January 18, 2011 This is what i have now, but getting a 404 error page <?php require_once('contact.php');?> Reset Submit Link to comment Share on other sites More sharing options...
SupraShaun Posted January 18, 2011 Share Posted January 18, 2011 When you submit the form or just when you view the page? Link to comment Share on other sites More sharing options...
bondango Posted January 18, 2011 Author Share Posted January 18, 2011 When you submit the form or just when you view the page? yeah its On submit Shaun Link to comment Share on other sites More sharing options...
SupraShaun Posted January 18, 2011 Share Posted January 18, 2011 Hmm, put this underneath if(isset($_POST['email'])) { at the top of contact.php to check your getting that far and see whats in the post: print ''; print_r($_POST); print ''; exit(); Link to comment Share on other sites More sharing options...
bondango Posted January 18, 2011 Author Share Posted January 18, 2011 No output, just the 404 page shaun Link to comment Share on other sites More sharing options...
SupraShaun Posted January 18, 2011 Share Posted January 18, 2011 Hmm, odd. On line 36 you have short php tags () change them to full php tags, so <?php Link to comment Share on other sites More sharing options...
bondango Posted January 18, 2011 Author Share Posted January 18, 2011 Hmm, odd. On line 36 you have short php tags () change them to full php tags, so <?php Shaun im just using a basic editor so no line numbers, but cannot find those short tags in my html just 2 full ones <?php Link to comment Share on other sites More sharing options...
SupraShaun Posted January 18, 2011 Share Posted January 18, 2011 Its right at the bottom of contact.php Link to comment Share on other sites More sharing options...
bondango Posted January 18, 2011 Author Share Posted January 18, 2011 changed, still getting a 404.host.com/? page Link to comment Share on other sites More sharing options...
SupraShaun Posted January 18, 2011 Share Posted January 18, 2011 Are both files in the same directory? Just for testing purposes put the whole link in the form action, e.g. http://www.domain.com/contact.php Link to comment Share on other sites More sharing options...
bondango Posted January 18, 2011 Author Share Posted January 18, 2011 yep shaun both in root directory. this is the error when domain/contact.php i Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in /home/a9209579/public_html/contact.php on line 3 Link to comment Share on other sites More sharing options...
SupraShaun Posted January 18, 2011 Share Posted January 18, 2011 Post the contents of contact.php and I'll have a gander Link to comment Share on other sites More sharing options...
bondango Posted January 18, 2011 Author Share Posted January 18, 2011 think i'll stick to cars... <?php echo "arrived?" if(isset($_POST['email'])) { print ''; print_r($_POST); print ''; exit(); // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "Scrap/damaged/sale query"; $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "contact: ".clean_string($phone)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "postcode".clean_string($post)."\n"; $email_message .= "Vehicle: ".clean_string($vehicle)."\n"; $email_message .= "Reg: ".clean_string($reg)."\n"; $email_message .= "Other: ".clean_string($other)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> } ?> Link to comment Share on other sites More sharing options...
SupraShaun Posted January 18, 2011 Share Posted January 18, 2011 Here you go: <?php if(isset($_POST['email'])) { print ''; print_r($_POST); print ''; exit(); // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "[email protected]"; $email_subject = "Scrap/damaged/sale query"; $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "contact: ".clean_string($phone)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "postcode".clean_string($post)."\n"; $email_message .= "Vehicle: ".clean_string($vehicle)."\n"; $email_message .= "Reg: ".clean_string($reg)."\n"; $email_message .= "Other: ".clean_string($other)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> Include your own success html here <?php } ?> Link to comment Share on other sites More sharing options...
SupraShaun Posted January 18, 2011 Share Posted January 18, 2011 Remove the following for the whole script to run: print ''; print_r($_POST); print ''; exit(); Link to comment Share on other sites More sharing options...
bondango Posted January 18, 2011 Author Share Posted January 18, 2011 done shaun. com/contact.php shows no errors, but when submitting, going to 404 page Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now