peschomd Posted August 15, 2007 Share Posted August 15, 2007 Hi everyone, I'm new here. I am trying to make the form fields "First name, last name, state, phone, and email" required. the page is here http://www.mankatowebdesign.com/SMS/central_midwest_region.html The PHP Code I have currently my friend helped me so I know the (if) statements need to be fixed. If anyone could explain what I need to change the if's to to fix this it would help. <?php $txtCompanyName = $_POST["txtCompanyName"]; $txtFirstName = $_POST["txtFirstName"]; $txtLastName = $_POST["txtLastName"]; $txtTitle = $_POST["txtTitle"]; $txtStreetAddress = $_POST["txtStreetAddress"]; $txtCity = $_POST["txtCity"]; $txtState = $_POST["txtState"]; $txtZip = $_POST["txtZip"]; $txtCountry = $_POST["txtCountry"]; $txtPhone = $_POST["txtPhone"]; $txtEmailAddress = $_POST["txtEmailAddress"]; $txtNumberOfEmployees = $_POST["txtNumberOfEmployees"]; $chkContactMeChoicesA = $_POST["ChkContactMeChoicesA"]; $chkContactMeChoicesB = $_POST["ChkContactMeChoicesB"]; $chkContactMeChoicesC = $_POST["ChkContactMeChoicesC"]; $chkContactMeChoicesD = $_POST["ChkContactMeChoicesD"]; $txtContactMeChoicesD1 = $_POST["txtContactMeChoicesD1"]; $txtHearAboutUs = $_POST["HearAboutUs"]; $txtHearAboutUsOther = $_POST["txtHearAboutUsOther"]; $txtComments = $_POST["txtComments"]; if($txtHearAboutUs == "No Selection" || $txtRegionalManager == "No Selection") { echo "<h2>One or more required fields are missing. Please hit 'back' on your browser and fill in all required fields.</h2>\n"; } $ContactMeChoiceFormatted = ""; if(!empty($chkContactMeChoicesA)) { $ContactMeChoiceFormatted = $chkContactMeChoicesA; } if(!empty($chkContactMeChoicesB)) { $ContactMeChoiceFormatted = $ContactMeChoiceFormatted .", ". $chkContactMeChoicesB; } if(!empty($chkContactMeChoicesC)) { $ContactMeChoiceFormatted = $ContactMeChoiceFormatted .", ". $chkContactMeChoicesC; } if(!empty($chkContactMeChoicesD)) { $ContactMeChoiceFormatted = $ContactMeChoiceFormatted .", ". $chkContactMeChoicesD . $txtContactMeChoicesD1; } $todayis = date("l, F j, Y, g:i a") ; $message = " $todayis [EST] \n Company: $txtCompanyName ----------------------------------- From: $txtLastName, $txtFirstName ($txtEmailAddress) ----------------------------------- Phone: $txtPhone ----------------------------------- Title: $txtTitle ----------------------------------- Address: $txtStreetAddress $txtCity, $txtState, $txtZip, $txtCountry ----------------------------------- Number Of Employees: $txtNumberOfEmployees ----------------------------------- Please Contact Me Regarding: $ContactMeChoiceFormatted ----------------------------------- How Did I Hear About SMS: $txtHearAboutUs ----------------------------------- If Other: $txtHearAboutUsOther ----------------------------------- Comments: $txtComments ----------------------------------- "; mail("ddooley@scholarshipamerica.org", "SMS Web Request", $message, $txtEmailAddress); ?> <!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 name="keywords" content="tuition assistance,loan programs,scholarship management,sms,scholarship america"> <meta name="description" content="Scholarship Management Services provides scholarship management, tuition assistance, loan programs, and case studies about our clients."> <link type="text/css" href="http://www.mankatowebdesign.com/SMS/style.css" rel="stylesheet" media="screen" /> <title>Thank You For Your Message</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="shortcut icon" href="favicon.ico" > </head> <body> <div id="container"> <div class="navigation"> <a href="contact.html">Contact</a> | <a href="faq.html">FAQ</a> | <a href="newsletter.html">Newsletter</a> | <a href="refer_this_site.html">Refer This Site</a></div> <div id="header" > <img border="0" src="services.gif"></div> <div id="left"><div class="top_tier"> <a href="index.html">Home</a></div> <div class="top_tier"> <a href="services.html">Services</a></div> <div class="bottom_tier1"> <a href="scholarships.html">Scholarships</a></div> <div class="bottom_tier"> <a href="tuition_assistance.html">Tuition Assistance</a></div> <div class="bottom_tier"> <a href="loan_programs.html">Loan Programs</a></div> <div class="top_tier"> <a href="sms_advantage.html">SMS Advantage</a></div> <div class="top_tier"> <a href="about.html">About Us</a></div> <div class="bottom_tier"> <a href="leadership.html">Leadership</a></div> <div class="bottom_tier"> <a href="job_opportunities.html">Job Opportunities</a></div> <div class="top_tier"> <a href="case_studies.html">Case Studies</a></div> <div class="top_tier"> <a href="news.html">News & Events</a></div> <div class="bottom_tier"> <a href="newsletter.html">Newsletter</a></div> <div class="top_tier"> <a target="_blank" href="http://scholarshipamerica.org/students/index.html">Student Resources</a></div> <div class="top_tier"> <a href="refer_this_site.html">Refer This Site</a></div> <div class="top_tier"> <a href="faq.html">FAQs</a></div> <div class="top_tier"> <a href="contact.html">Contact Us</a></div> <p> <br /> <br /> </p> <div align="center"><a target="_blank" href="http://www.scholarshipamerica.org"> <img src="scholarshiplogo.jpg" border="0" alt="Scholarship America" /></a></div> </div> <div id="right" style="width: 181px; height: 459px"> <h2> </h2> </div> <div id="content_index"> <div class="hierarchy"> Viewing: <a href="index.html">Home</a> > <a href="contact.html">Contact Us</a> > Thank You </div> <p><font size="4" color="#A5262F"><b>Thank You For Your Message!<br> <br> </b></font><font size="2">Your message has been received. </font></p> <p> </p> <p> </p> </div> <div id="footer"><font size="1">Registered </font><span style="font-family: Arial"><font style="font-size: 9pt"></font></span><font size="1"> 2007 Scholarship Management Services | <a href="index.html">Home</a> | <a href="contact.html">Contact Us</a> | <a href="sitemap.html">Sitemap</a> | <a href="privacy_policy.html">Privacy Policy</a><br /> </font> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/65132-making-my-form-fields-required/ Share on other sites More sharing options...
lemmin Posted August 15, 2007 Share Posted August 15, 2007 Currently you are only checking to make sure "$txtHearAboutUs" or "$txtRegionalManager" is valid. Use that same if statement to check the other ones. For the text fields it is probably better to check using the isset(), however, you are setting your own variables to th epost variables without checking them. I would assume this code would give an error if you left a box empty. I would suggest checking the $_POST array itself before setting your variables: if(!isset($_POST['txtHearAboutUs']) || !isset($_POST['txtRegionalManager']) || !isset($_POST['txtFirstName'])) You can make that if statement as big as you want, putting in whatever fields you want to check. Quote Link to comment https://forums.phpfreaks.com/topic/65132-making-my-form-fields-required/#findComment-325109 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.