crumpy1 Posted January 27, 2012 Share Posted January 27, 2012 Where can i find free templates for php code that simply submits a forms content on submit. It does not need to validate fields that are not complete or anything as this has been coded into my html. I need it to send a copy of the form to the senders address i.e 'email' id and to myself. I have been using code that validates if ALL fields are complete and it is forcing users to complete even the non-mandatory fields on sumbit which i do not want or need. Also i forgot to say that there are two webpages with the Location:() tags one for successfully sent and other for failed but i can add these in myself if i cannot find template with them already included. Any help would be appreciated. Thanks to anyone who helps. Quote Link to comment https://forums.phpfreaks.com/topic/255886-mail-form-template-php/ Share on other sites More sharing options...
spiderwell Posted January 27, 2012 Share Posted January 27, 2012 why not remove the validation from what you have already Quote Link to comment https://forums.phpfreaks.com/topic/255886-mail-form-template-php/#findComment-1311705 Share on other sites More sharing options...
crumpy1 Posted January 27, 2012 Author Share Posted January 27, 2012 why not remove the validation from what you have already Sorry i should have mensioned that i am only a student and have been using the college templates to sumbit my form. Attached is a copy of the code i have been using, but it keeps forcing me to complete all fields. I do not understand php yet only the very very basics. If you do not mind tweaking this for me it would be appreciated, just to submit the form to myself and the sender ('email' id) and to send them to the appropiate webpage. Alternativly as i know it is a bit of a cheeck if you can let me know where to find templates to suit my needs that also will be hugely appreciated. Thanks 17435_.php Quote Link to comment https://forums.phpfreaks.com/topic/255886-mail-form-template-php/#findComment-1311741 Share on other sites More sharing options...
Pikachu2000 Posted January 27, 2012 Share Posted January 27, 2012 You seem to be confused as to what a help forum is. We're here to help people fix code, not fix code for people. Quote Link to comment https://forums.phpfreaks.com/topic/255886-mail-form-template-php/#findComment-1311746 Share on other sites More sharing options...
crumpy1 Posted January 29, 2012 Author Share Posted January 29, 2012 You seem to be confused as to what a help forum is. We're here to help people fix code, not fix code for people. I appreciate that, thats why i asked for pre made templates or free use code that i can implement on my own pages! Some people prefer to tweak whats already there that why i gave both as an option! Quote Link to comment https://forums.phpfreaks.com/topic/255886-mail-form-template-php/#findComment-1312317 Share on other sites More sharing options...
AyKay47 Posted January 30, 2012 Share Posted January 30, 2012 if you post the code to this thread, we can certainly assist you. Quote Link to comment https://forums.phpfreaks.com/topic/255886-mail-form-template-php/#findComment-1312428 Share on other sites More sharing options...
crumpy1 Posted January 30, 2012 Author Share Posted January 30, 2012 if you post the code to this thread, we can certainly assist you. Thank you, i never expected people to do it all for me, i need to learn how to do it for myself and want to. I have re-attached it for you to see. I want it to be a submit form only, i do not want it to validate any of the forms on submit and i want to be able to sent it to an address in my 'email' field as well as my own. then go to a page that either confirms it has been sent ok or failed to send. Thanks 17446_.php Quote Link to comment https://forums.phpfreaks.com/topic/255886-mail-form-template-php/#findComment-1312498 Share on other sites More sharing options...
AyKay47 Posted January 30, 2012 Share Posted January 30, 2012 Again: if you post the code to this thread, we can certainly assist you. Paste the code into this thread, don't attach it. Quote Link to comment https://forums.phpfreaks.com/topic/255886-mail-form-template-php/#findComment-1312548 Share on other sites More sharing options...
crumpy1 Posted January 30, 2012 Author Share Posted January 30, 2012 Again: if you post the code to this thread, we can certainly assist you. Paste the code into this thread, don't attach it. Sorry did not relise that is what you mean't. <? error_reporting(E_ALL); /****************************************************** ******** Secure mailing script ***************** ******** Copyright David Wilde ***************** ******************************************************* You can add your template to this page. Make your form action value the absolute or relative path to the location of this script once it is uploaded to your site. Example; Absolute path: <form method="post" action="http://www.yourdomain.com/scripts/mailprocess.php"> OR relative path: <form method="post" action="scripts/mailprocess.php"> Assuming you have a scripts folder and you upload the script to that folder. The script Checks that all fields contain information and validates the email address. You must have the email text field in your form set with the name of 'email' the name is case sensative, so make sure it is in lowercase. */ ################################################################################### // Start config variables // ONLY CHANGE THE DETAILS IN BETWEEN THE QUOTES; E.G 'your@email-address.com' // $to='admin@localhost'; // You must change this! This should be the email address you want the form information sent to. // $subjectline='Web site form - Contact Us'; // The email subject line. You may leave this as is. // #################################################################################### ## Do Not Edit Below this Line ## #################################################################################### // $thanks="<h1> We have received your message.</h1><br /> <p>We will deal with it as soon as possible</p> <p><ul><li>Go <a href='/'>Back</a> back to the Home Page/li></ul>"; // This is the message given after successfull submission of form. // The ['email'] should match the name= in the email text input box in your form. Used for email validation. // DO NOT CHANGE THIS HERE. Change your form to match this. $email = $_POST['email'] ; // collect users email from form for the email header. // Collect all information from form and check all fields have been filled in. if (sizeof($_POST)) { $body = ""; while(list($key, $val) = each($_POST)) { if ($key == "Submit") { //do nothing } else { $body .= "$key:\n $val\r\n"; // Checks if $val contains data if(empty($val)) { echo ("<b><p><li>One or more required fields have not been filled in.</li></p> <p><li>Please go <a href='javascript: history.go(-1)'>Back</a> and try again</li></p></b>"); exit(); } } }} // Validate email address if(!preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$/",$email)){ echo ("<b><li>Invalid email address entered. Go <a href='javascript: history.go(-1)'>Back</a> and try again</li></b>"); exit(); } // Clean up email address if (get_magic_quotes_gpc()){ $email = stripslashes($email); } // Set headers $security = "From: ".$email."\r\n"; $security .= "Reply-To: ".$email."\r\n"; $security .= "Return-Path: \r\n"; $security .= "CC: \r\n"; $security .= "BCC: \r\n"; ini_set("sendmail_from", $email); // Send the email. if ( mail($to, $subjectline, $body, $security, "-f".$email)) { header('Location:http://localhost/HFCC/Email_Responses/Employee_App_Response.html'); //Message if mail has been sent sucsessfully. } else { header('Location:http://localhost/HFCC/Email_Responses/failed.html'); // Message If mail not sent } ?> Quote Link to comment https://forums.phpfreaks.com/topic/255886-mail-form-template-php/#findComment-1312568 Share on other sites More sharing options...
AyKay47 Posted January 30, 2012 Share Posted January 30, 2012 what part of this code do you need help with or do not understand? Quote Link to comment https://forums.phpfreaks.com/topic/255886-mail-form-template-php/#findComment-1312571 Share on other sites More sharing options...
crumpy1 Posted January 31, 2012 Author Share Posted January 31, 2012 what part of this code do you need help with or do not understand? I need help to remove the validation checks that force users to fill in all fields. And how to send a copy of it back to the original sender as well as me on sumbit. Quote Link to comment https://forums.phpfreaks.com/topic/255886-mail-form-template-php/#findComment-1312880 Share on other sites More sharing options...
AyKay47 Posted January 31, 2012 Share Posted January 31, 2012 what part of this code do you need help with or do not understand? I need help to remove the validation checks that force users to fill in all fields. And how to send a copy of it back to the original sender as well as me on sumbit. while(list($key, $val) = each($_POST)) { if ($key == "Submit") { //do nothing } else { $body .= "$key:\n $val\r\n"; // Checks if $val contains data if(empty($val)) { echo ("<b><p><li>One or more required fields have not been filled in.</li></p> <p><li>Please go <a href='javascript: history.go(-1)'>Back</a> and try again</li></p></b>"); exit(); } } this bit here checks if all fields have been filled out, you can replace this bit with whatever validation you want. you can CC the email to you and the original sender in the $headers part of the email. Quote Link to comment https://forums.phpfreaks.com/topic/255886-mail-form-template-php/#findComment-1312917 Share on other sites More sharing options...
crumpy1 Posted January 31, 2012 Author Share Posted January 31, 2012 Thank you for the help I have finally got the code working for 2 out of the 3 forms. The 1 form keeps producing 'object not found error 404' on submit. The form is in the same root folder as the other pages and share the same php code however when the others say sent sucsessfully this one gives the error message. Are there any obvious things with this error? The location of the php file in action is definetly correct and the method is set to POST. Quote Link to comment https://forums.phpfreaks.com/topic/255886-mail-form-template-php/#findComment-1313010 Share on other sites More sharing options...
crumpy1 Posted January 31, 2012 Author Share Posted January 31, 2012 Thank you for the help I have finally got the code working for 2 out of the 3 forms. The 1 form keeps producing 'object not found error 404' on submit. The form is in the same root folder as the other pages and share the same php code however when the others say sent sucsessfully this one gives the error message. Are there any obvious things with this error? The location of the php file in action is definetly correct and the method is set to POST. All 3 working correctly now, thank you to you all for your help! Quote Link to comment https://forums.phpfreaks.com/topic/255886-mail-form-template-php/#findComment-1313014 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.