Fitch Posted September 2 Share Posted September 2 (edited) Hi. I've been thrown in the deep end with a community shed website when the person who knows HTML bailed out I have very little knowledge of writing forms - none actually. I've done my best at writing (plagarising) an application form with no success. Can someone give me a heads up where I've gone wrong? This is the application HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title>Application</title> <meta content="Alistair" name="author"> <style> body { background-color:rgb(102, 255, 255); } ul { list-style-type: none; display: flex; margin: 70; padding: 60; overflow: hidden; spacing: 120; # background-color:rgb(102, 255, 255); } li { float: left; } li { margin-right: 110px; } li a, .dropbtn { display: inline-block; color: black; text-align: center; padding: 14px 16px; text-decoration: none; } li a:hover, .dropdown:hover .dropbtn { background-color: grey; } li.dropdown { display: inline-block; } .dropdown-content { display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1; } .dropdown-content a { color: black; padding: 12px 16px; text-decoration: none; display: block; text-align: left; } .dropdown-content a:hover {background-color: #f1f1f1;} .dropdown:hover .dropdown-content { display: block; } </style> </head> <body style="margin-left: 0px; width: 1303px;"> <table style="width: 1280px; height: 129px;" border="0"> <tbody> <tr> <td style="width: 377.25px; text-align: right;"><img style="width: 302px; height: 115px;" alt="Logo" src="Images/logo.png"></td> <td style="width: 560.883px;"> <div style="text-align: center;"><font size="+3"><span style="font-family: serif;"><span style="font-family: Helvetica,Arial,sans-serif;">Livingston Community Shed <div style="text-align: center;"><small style="font-family: sans-serif;">Application Form</small><br> </div> <font size="+3"><span style="font-family: serif;"><span style="font-family: Helvetica,Arial,sans-serif;"></span></span></font></span></span></font></div> <big> <font size="+3"> <font size="+3"><span style="font-family: serif;"></span></font> </font></big></td> <td style="width: 402.867px; text-align: left;"><span><img src="Images/smsa-logo.png" alt="smsa logo" style="width: 279px; height: 102px;"><br> </span></td> </tr> </tbody> </table> <ul> <li style="font-weight: bold;"><big><a href="index.html">Home</a></big></li> <li style="font-weight: bold;"><big><a href="about.html">About</a></big></li> <li style="font-weight: bold;"><big><a href="findus.html">Find Us</a></big></li> <big> </big> <li style="font-weight: bold;" class="dropdown"><big> <a href="javascript:void(0)" class="dropbtn">News</a></big> <div style="top: 178px; left: 671px;" class="dropdown-content"><a href="updates.html">Updates</a><a href="projects.html">Projects</a><a href="gardens.html">Gardens</a><a href="videos.html">Videos</a></div> </li> <li style="font-weight: bold;"><big><a href="join.html">Join</a></big></li> <big> <big> </big> </big> <li style="font-weight: bold;"><big><a href="contact.html">Contact</a></big></li> </ul> <div style="text-align: center;"><!-- ************ End of Headings ************** --> <br> <big><big><big><span style="font-family: Helvetica,Arial,sans-serif; color: rgb(51, 51, 255); font-weight: bold;">Livingston Community Shed Application Form</span></big></big></big> </div> <div style="text-align: center; width: 1199px;"><br> </div> <table style="text-align: left; width: 900px; margin-left: auto; margin-right: auto;" cellpadding="2" cellspacing="2"> <tbody> <tr> <td style="vertical-align: top; width: 464px;"> <form style="margin-left: 0px; width: 410px;"><!-- ************ Forename ************** --> <div style="margin-left: 0px; width: 391px;"> <div style="text-align: left;"> <label for="fname">First name:</label><br> </div> <div style="text-align: left;"><input id="fname" name="fname" value="" type="text"><br> <br> </div> <!-- ************ Surname ************** --> <div style="text-align: left;"><label for="sname">Surname:</label><br> </div> <div style="text-align: left;"><input id="sname" name="sname" value="" type="text"><br> <br> </div> <!-- ************ Address 1 ************** --> <div style="text-align: left;"> <label for="add1">Address 1:</label><br> </div> <div style="text-align: left;"><input size="30" id="add1" name="add1"><br> <br> </div> <!-- ************ Address 2 ************** --> <div style="text-align: left;"><label for="add2">Address 2:</label><br> </div> <div style="text-align: left;"><input size="30" id="add2" name="add2"><br> <br> </div> <!-- ************ Town ************** --> <div style="text-align: left;"> <label for="town">Town / City:</label><br> </div> <div style="text-align: left;"><input id="town" name="town" value="" type="text"><br> <br> </div> <!-- ************ Postcode ************** --> <div style="text-align: left;"><label for="pcode">Postcode:</label><br> </div> <div style="text-align: left;"><input size="8" name="pcode" id="pcode"><br> <br> </div> <!-- ************ email ************** --> <div style="text-align: left;"><label for="email">Email:<br> <input id="email" name="email" type="email"><br> </label></div> <!-- ************ Phone number ************** --> <div style="text-align: left;"><label for="phone">Phone Number:</label><br> </div> <div style="text-align: left;"><input size="15" name="phone" id="phone" type="tel"><br> <br> </div> <!-- ************ Birthday ************** --> <div style="text-align: left;"><label for="bday">Date of Birth:</label><br> </div> <div style="text-align: left;"><input size="8" id="bday" name="bday" value="" type="date"><br> <br> </div> </div> </form> </td> <td style="vertical-align: top; width: 632px;"> <form style="width: 529px;"> <label for="cname">Contact name:</label><br> <input id="cname" name="cname" value="" type="text"><br> <br> <label for="relat">Relationship:</label><br> <input id="relat" name="relat" value="" type="text"> <br> <br> <label for="cphone">Contact Phone Number:</label><br> <input id="cphone" name="cphone" type="tel"> <span style="font-weight: bold;"><br> <br> </span> <div><label for="allergy">Please list any allergies you may have:<br> </label> <div style="text-align: left; margin-left: 0px; width: 978px;" class="fcf-input-group"> <textarea cols="30" id="allergy" name="allergy" class="fcf-form-control" rows="5" maxlength="1000" required=""></textarea> </div> <br> <label for="skill">Please list any skills/interests which may be useful to the shed:</label><br> <div style="text-align: left; margin-left: 0px; width: 978px;" class="fcf-input-group"> <textarea cols="30" id="skill" name="skill" class="fcf-form-control" rows="5" maxlength="1000" required=""></textarea> </div> <br> </div> </form> </td> </tr> </tbody> </table> <table style="text-align: left; width: 950px; margin-left: auto; height: 31px; margin-right: auto;" cellpadding="2" cellspacing="2"> <tbody> <tr> <td style="vertical-align: top; width: 874px;"><input id="permit" name="permit" value="No" type="checkbox"> <label for="permit">May we include a summary of this and a photo in the member’s section of the website?</label><br> </td> </tr> </tbody> </table> <table style="text-align: left; height: 151px; margin-right: auto; width: 950px; margin-left: auto;" cellpadding="2" cellspacing="2"> <tbody> <tr> <td colspan="1" rowspan="1" style="vertical-align: top; text-align: center; width: 950px;"> <p style="line-height: 100%; margin-bottom: 0cm;" align="left"><font style="font-size: 14pt;" size="4"><b>Constitution acceptance</b></font></p> <span style="font-weight: bold;"></span> <p style="line-height: 100%; margin-bottom: 0cm;" align="left"><font style="font-size: 12pt;" size="3"><input id="perm" name="agree" value="No" type="checkbox"> <label for="agree">I agree to abide by the constitution of the Livingston Community Shed, a copy of which is held in the shed and on this Website.</label><br> </font><br> </p> <p style="line-height: 100%; margin-bottom: 0cm;" align="left"><font style="font-size: 12pt;" size="3"><input id="smsa" name="smsa" value="No" type="checkbox"><label for="smsa">By applying, I also agree to abide by the Scottish Men’s Sheds Association (SMSA) Constitution and Purposes to which we are affiliated with group membership.</label></font></p> <form style="margin-top: 16px; height: 55px;" enctype="text/plain" method="post" action="/application.php"> <input style="height: 50px; width: 70px;" value="Submit" align="middle" type="submit"><br> <!-- **** If you click the "Submit" button, the form-data will be sent to a page called "/application.php **** --> </form> </td> </tr> </tbody> </table> </body> </html> The PHP page that accompanies it is: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <?php if (isset($_POST['Email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "merg.eosag@gmail.com"; $email_subject = "New Application Request."; function problem($error) { echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br><br>"; echo $error . "<br><br>"; echo "Please go back and fix these errors.<br><br>"; die(); } // validation expected data exists if ( !isset($_POST['fname']) || !isset($_POST['sname']) || !isset($_POST['email']) || !isset($_POST['bday']) || !isset($_POST['agree']) || !isset($_POST['smsa']) ) { problem('We are sorry, but there appears to be a problem with the form you submitted.'); } $fname = $_POST['fname']; // required $sname = $_POST['sname']; // required $email = $_POST['email']; // required $fname = $_POST['bday']; // required $sname = $_POST['agree']; // required $email = $_POST['smsa']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if (!preg_match($email_exp, $email)) { $error_message .= 'The Email address you entered does not appear to be valid.<br>'; } $string_exp = "/^[A-Za-z .'-]+$/"; if (!preg_match($string_exp, $fname)) { $error_message .= 'The Name you entered does not appear to be valid.<br>'; } $string_exp = "/^[A-Za-z .'-]+$/"; if (!preg_match($string_exp, $sname)) { $error_message .= 'The Name you entered does not appear to be valid.<br>'; } $string_exp = ""; if(!preg_match($string_exp,$bday)) { $error_message .= 'You did not choose a date.<br />'; } if (isset($_POST['agree'])) { // Checkbox is checked } else { $error_message .= 'You did not agree to the constitution.<br>'; } if (isset($_POST['smsa'])) { // Checkbox is checked } else { $error_message .= 'You did not agree to the SMSA rules.<br>'; } $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 .= "Foreame: " . clean_string($fname) . "\n"; $email_message .= "Surname: " . clean_string($sname) . "\n"; $email_message .= "Address1: " . clean_string($add1) . "\n"; $email_message .= "Address2: " . clean_string($add2) . "\n"; $email_message .= "Town: " . clean_string($town) . "\n"; $email_message .= "Postcode: " . clean_string($pcode) . "\n"; $email_message .= "Email: " . clean_string($email) . "\n"; $email_message .= "Phone Number: " . clean_string($phone) . "\n"; $email_message .= "Date of Birth: " . clean_string($bday) . "\n"; $email_message .= "Contact Name: " . clean_string($cname) . "\n"; $email_message .= "Relationship: " . clean_string($relat) . "\n"; $email_message .= "Contact Phone: " . clean_string($cphone) . "\n"; $email_message .= "Allergies: " . clean_string($allergy) . "\n"; $email_message .= "Skills: " . clean_string($skill) . "\n"; $email_message .= "Page Permission: " . clean_string($permit) . "\n"; $email_message .= "Abide by LCS Rules: " . clean_string($agree) . "\n"; $email_message .= "Abide by SMSA Rules: " . clean_string($smsa) . "\n"; // create email headers $headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?><!-- include your success message below --> <title>Application.php</title> </head> <body style="color: rgb(0, 0, 0); background-color: rgb(102, 255, 255);" alink="#000099" link="#000099" vlink="#990099"> <br> <div style="text-align: center;"><?php } ?> <br> <br> <big>Thank you for your application. We will be in touch with you very soon. <br> </big> </div> <div style="text-align: center;"><big><a href="index.html"><br> Back to Home page</a></big><br> </div> </body> </html> Â Â Edited September 2 by Fitch Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/ Share on other sites More sharing options...
requinix Posted September 2 Share Posted September 2 It'll be hard to tell you what you've done wrong without a description of what's happening... Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1634462 Share on other sites More sharing options...
Fitch Posted September 2 Author Share Posted September 2 (edited) Hi again Being a newbie. I'm not sure what you need to know. The actual website is www.livingstoncommunityshed.scot/application.html When anyone fills in the form, it is never sent. Edited September 2 by Fitch Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1634466 Share on other sites More sharing options...
requinix Posted September 2 Share Posted September 2 What we need to know is 6 minutes ago, Fitch said: When anyone fills in the form, it is never sent. that. To be blunt, we can't help you solve a problem if you don't tell us what the problem is. Â I'm guessing that when you say "it is never sent", you mean "I always receive the 'there appears to be a problem with the form' message even when I fill out all the fields"? Three things: 1. Only one <form> can be submitted at a time 2. Only the fields inside of that <form> will be included in the submission 3. When you click a submit button, its parent <form> is the one that gets submitted - if there is one For the record, the actual rules are a little more complicated, but the above covers most situations. Including this one. Considering the above, it should make sense you don't get any data: the Submit button isn't in a form at all, but if it was, you've split the fields between multiple <form> elements. Form elements don't have any meaning when it comes to (visually) designing a page, so you can put them anywhere you want. Have one single <form> that covers the entire form, with all the fields and the submit button. Use it to "wrap" the entire application form. Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1634468 Share on other sites More sharing options...
Fitch Posted September 2 Author Share Posted September 2 (edited) It actually says "Thank you for your application. We will be in touch with you very soon." I have no idea what you said after that. http://www.livingstoncommunityshed.scot/application.html Edited September 2 by Fitch Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1634469 Share on other sites More sharing options...
mac_gyver Posted September 2 Share Posted September 2 what is your goal for doing this? to have a working form to email application or to learn programming? if it's to have a working, secure, application, you need to hire someone or use an existing service. if it is to learn how to do this, i recommend that you start with a blank page (don't copy/paste out-of-date things you find on the web), and get the code to fully work for a single form field, then worry about adding all the code necessary for the rest of the fields. some points for creating an application - put the form processing code and the form on the same page. the code for any page should be laid out in this general order - 1) initialization, 2) post method form processing, 3) get method business logic - get/produce data needed to display the web page, 4) html document validate any web page you create at validator.w3.org the form processing code should detect if a post method form was submitted before referencing any of the form data. keep the form data as a set in a php array variable, then operate on elements in this array variable throughout the rest of the code, i.e. don't create discrete variables for every form field. trim all the input data before validating it. once you do item #4 on this list, you can trim all the data using a single line of code. validate the now trimmed data, store user/validation errors in an array using the field name as the array index. don't roll your own email valuation. use php's filter_var() with the FILTER_VALIDATE_EMAIL flag. after the end of the validation logic, if there are no errors (the array holding the user/validation errors will be empty), use the submitted form data. any value you use in a html context (web page, email) needs to have htmlentities() applied to it, right before being used, to help prevent cross site scripting. these emails are not being sent from the email address that someone entered in the form. they are being sent from the mail server at your web hosting. the From: mail header must be an email address that corresponds to your web hosting. the Reply-to: mail header can be set to the entered email address. don't use the php @ error suppressor, ever. you must test the returned value from the mail() call and take an appropriate action depending on the value. if it is a false value, you need to setup a message for the user (add it to the array holding the user/validation errors) that the email was unsuccessful. for a true value, you would let the post method form processing code run to completion. at the end of the form processing code, if there are no errors, you need to perform a redirect to the exact same URL of the current page to cause a get request. this will prevent the browser from trying to resubmit the form data should the URL get browsed back to or reloaded. to display a one-time success message, either store a flag value or the message in a session variable, then test for, display the success message, and clear the session variable at the appropriate location in the html document. if there are user/validation errors at item #8 or #13 on this list, the code will continue on to redisplay the html document, where you would test for and display the user/validation errors, and redisplay the form, populating field values, select choices, checkbox/radio fields with any existing data, so that the user doesn't need to keep reentering/reselecting data over and over upon an error. as an advanced programming subject, if you have more than 2-3 fields, you need to dynamically - validate and process the form data, and dynamically build the form. Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1634471 Share on other sites More sharing options...
Solution maxxd Posted September 2 Solution Share Posted September 2 In addition to everything requinix and mac_gyver have mentioned, you have several different <form></form> elements in your HTML - this is incorrect. There should be one form that encompasses all the input fields in your form. The reason you're getting the success message every time is that the form element that surrounds the submit button contains only the submit button - the Email field is in a different form (I'm assuming - your formatting got weird and hard to follow). Add the following right before the `<?php if(isset($_POST['Email']) {` line in application.php: <pre><?php var_export($_POST, true); ?></pre> Â Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1634472 Share on other sites More sharing options...
Fitch Posted September 3 Author Share Posted September 3 Thanks. I've deleted the extra "form"s and put that line in the php file. I'll give it a try tomorrow from outside as I can't access the website from the same LAN as the server is on. Sorry to be such an idiot on this. I'll mark it solved and won't bother you again. Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1634475 Share on other sites More sharing options...
Moorcam Posted September 4 Share Posted September 4 On 9/3/2024 at 10:02 AM, Fitch said: Thanks. I've deleted the extra "form"s and put that line in the php file. I'll give it a try tomorrow from outside as I can't access the website from the same LAN as the server is on. Sorry to be such an idiot on this. I'll mark it solved and won't bother you again. No such thing as an idiot unless you are me Try this: <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Application.php</title> </head> <body style="color: #000; background-color: #66FFFF;"> <?php if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Define recipient and subject $email_to = "merg.eosag@gmail.com"; $email_subject = "New Application Request."; // Function to handle errors function handleError($error) { echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below:<br><br>"; echo $error . "<br><br>"; echo "Please go back and fix these errors.<br><br>"; die(); } // Validate required fields $required_fields = ['fname', 'sname', 'email', 'bday', 'agree', 'smsa']; foreach ($required_fields as $field) { if (!isset($_POST[$field])) { handleError('We are sorry, but there appears to be a problem with the form you submitted.'); } } // Sanitize and validate input $fname = cleanInput($_POST['fname']); $sname = cleanInput($_POST['sname']); $email = cleanInput($_POST['email']); $bday = cleanInput($_POST['bday']); $agree = isset($_POST['agree']) ? 'Yes' : 'No'; $smsa = isset($_POST['smsa']) ? 'Yes' : 'No'; $error_message = validateInput($fname, $sname, $email, $bday); if (!empty($error_message)) { handleError($error_message); } // Prepare email message $email_message = "Form details below:\n\n"; $email_message .= "First Name: $fname\n"; $email_message .= "Surname: $sname\n"; $email_message .= "Email: $email\n"; $email_message .= "Date of Birth: $bday\n"; $email_message .= "Agree to Terms: $agree\n"; $email_message .= "Agree to SMSA Rules: $smsa\n"; // Create email headers $headers = "From: $email\r\n" . "Reply-To: $email\r\n" . "X-Mailer: PHP/" . phpversion(); // Send email @mail($email_to, $email_subject, $email_message, $headers); echo "<div style='text-align: center;'><big>Thank you for your application. We will be in touch with you very soon.</big></div>"; echo "<div style='text-align: center;'><big><a href='index.html'>Back to Home page</a></big></div>"; } function cleanInput($data) { return htmlspecialchars(stripslashes(trim($data))); } function validateInput($fname, $sname, $email, $bday) { $error_message = ""; if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error_message .= 'The Email address you entered does not appear to be valid.<br>'; } if (!preg_match("/^[A-Za-z .'-]+$/", $fname)) { $error_message .= 'The First Name you entered does not appear to be valid.<br>'; } if (!preg_match("/^[A-Za-z .'-]+$/", $sname)) { $error_message .= 'The Surname you entered does not appear to be valid.<br>'; } if (empty($bday)) { $error_message .= 'You did not choose a date.<br>'; } return $error_message; } ?> </body> </html> Â Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1634680 Share on other sites More sharing options...
Fitch Posted September 6 Author Share Posted September 6 Hi Moorcam. I tried it and got: "; echo $error . " "; echo "Please go back and fix these errors. "; die(); } // Validate required fields $required_fields = ['fname', 'sname', 'email', 'bday', 'agree', 'smsa']; foreach ($required_fields as $field) { if (!isset($_POST[$field])) { handleError('We are sorry, but there appears to be a problem with the form you submitted.'); } } // Sanitize and validate input $fname = cleanInput($_POST['fname']); $sname = cleanInput($_POST['sname']); $email = cleanInput($_POST['email']); $bday = cleanInput($_POST['bday']); $agree = isset($_POST['agree']) ? 'Yes' : 'No'; $smsa = isset($_POST['smsa']) ? 'Yes' : 'No'; $error_message = validateInput($fname, $sname, $email, $bday); if (!empty($error_message)) { handleError($error_message); } // Prepare email message $email_message = "Form details below:\n\n"; $email_message .= "First Name: $fname\n"; $email_message .= "Surname: $sname\n"; $email_message .= "Email: $email\n"; $email_message .= "Date of Birth: $bday\n"; $email_message .= "Agree to Terms: $agree\n"; $email_message .= "Agree to SMSA Rules: $smsa\n"; // Create email headers $headers = "From: $email\r\n" . "Reply-To: $email\r\n" . "X-Mailer: PHP/" . phpversion(); // Send email @mail($email_to, $email_subject, $email_message, $headers); echo " Thank you for your application. We will be in touch with you very soon. "; echo " Back to Home page "; } function cleanInput($data) { return htmlspecialchars(stripslashes(trim($data))); } function validateInput($fname, $sname, $email, $bday) { $error_message = ""; if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error_message .= 'The Email address you entered does not appear to be valid. '; } if (!preg_match("/^[A-Za-z .'-]+$/", $fname)) { $error_message .= 'The First Name you entered does not appear to be valid. '; } if (!preg_match("/^[A-Za-z .'-]+$/", $sname)) { $error_message .= 'The Surname you entered does not appear to be valid. '; } if (empty($bday)) { $error_message .= 'You did not choose a date. '; } return $error_message; } ?> which is part of the PHP file isn't it? Thanks though, at least it got to the PHP file. Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1634849 Share on other sites More sharing options...
requinix Posted September 7 Share Posted September 7 8 hours ago, Fitch said: which is part of the PHP file isn't it? Yup. Which means it's not executing. Did you put this code into a file with a .php extension? Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1634862 Share on other sites More sharing options...
Fitch Posted September 7 Author Share Posted September 7 Yes. application.php Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1634892 Share on other sites More sharing options...
dodgeitorelse3 Posted September 8 Share Posted September 8 I see a closing php tag. Where is the opening php tag? Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1634895 Share on other sites More sharing options...
Fitch Posted September 8 Author Share Posted September 8 What does it look like, and which line do I put it? Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1634899 Share on other sites More sharing options...
mac_gyver Posted September 8 Share Posted September 8 where is the form and form process code hosted at? is on on the web site you previously posted the URL for? Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1634900 Share on other sites More sharing options...
Fitch Posted September 8 Author Share Posted September 8 (edited) Yes, it's there alongside application.html. I have a problem that I can't access the website to test as the server is on the same router as my desktop. I can only access it as FTP from the Asustor website. Edited September 8 by Fitch Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1634906 Share on other sites More sharing options...
Moorcam Posted September 17 Share Posted September 17 (edited) On 9/7/2024 at 7:15 AM, Fitch said: Hi Moorcam. I tried it and got: "; echo $error . " "; echo "Please go back and fix these errors. "; die(); } // Validate required fields $required_fields = ['fname', 'sname', 'email', 'bday', 'agree', 'smsa']; foreach ($required_fields as $field) { if (!isset($_POST[$field])) { handleError('We are sorry, but there appears to be a problem with the form you submitted.'); } } // Sanitize and validate input $fname = cleanInput($_POST['fname']); $sname = cleanInput($_POST['sname']); $email = cleanInput($_POST['email']); $bday = cleanInput($_POST['bday']); $agree = isset($_POST['agree']) ? 'Yes' : 'No'; $smsa = isset($_POST['smsa']) ? 'Yes' : 'No'; $error_message = validateInput($fname, $sname, $email, $bday); if (!empty($error_message)) { handleError($error_message); } // Prepare email message $email_message = "Form details below:\n\n"; $email_message .= "First Name: $fname\n"; $email_message .= "Surname: $sname\n"; $email_message .= "Email: $email\n"; $email_message .= "Date of Birth: $bday\n"; $email_message .= "Agree to Terms: $agree\n"; $email_message .= "Agree to SMSA Rules: $smsa\n"; // Create email headers $headers = "From: $email\r\n" . "Reply-To: $email\r\n" . "X-Mailer: PHP/" . phpversion(); // Send email @mail($email_to, $email_subject, $email_message, $headers); echo " Thank you for your application. We will be in touch with you very soon. "; echo " Back to Home page "; } function cleanInput($data) { return htmlspecialchars(stripslashes(trim($data))); } function validateInput($fname, $sname, $email, $bday) { $error_message = ""; if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error_message .= 'The Email address you entered does not appear to be valid. '; } if (!preg_match("/^[A-Za-z .'-]+$/", $fname)) { $error_message .= 'The First Name you entered does not appear to be valid. '; } if (!preg_match("/^[A-Za-z .'-]+$/", $sname)) { $error_message .= 'The Surname you entered does not appear to be valid. '; } if (empty($bday)) { $error_message .= 'You did not choose a date. '; } return $error_message; } ?> which is part of the PHP file isn't it? Thanks though, at least it got to the PHP file. Is that the actual error you got? It doesn't make sense. It just looks like php code showing on a html page. Paste the contents of application.php Edited September 17 by Moorcam Quote Link to comment https://forums.phpfreaks.com/topic/323784-application-form-problem/#findComment-1635416 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.