flowster Posted September 9, 2007 Share Posted September 9, 2007 Hi everyone, I posted last week regarding a problem i had with my form, Ive gone away, and took the time to get my php working as well as i can, only problem now, is when i submit my form, it keeps saying all fields need to be filled in, but everything is filled in, could one of you experts please take a look at my code tell me where im going wrong. <?php $txtFirstName=$_POST["txtFirstName"]; $surname=$_POST["surname"]; $txtAddress1=$_POST["txtAddress1"]; $txtAddress2=$_POST["txtAddress2"]; $postcode=$_POST["postcode"]; $txtCountry=$_POST["txtCountry"]; $txtTelephone=$_POST["txtTelephone"]; $txtMobile=$_POST["txtMobile"]; $txtEmail=$_POST["txtEmail"]; $txtproduct=$_POST["txtproduct"]; $brochure=$_POST["brochure"]; $radContactby=$_POST["radContactby"]; If ((!$txtFirstName) || (!$surname) || (!$txtAddress1) || (!$txtAddress2) || (!$postcode) || (!$txtCountry) || (!$txtMobile) || (!$txtEmail) || (!$txtproduct) || (!$radContactby) || (!$brochure) || (!$txtTelephone)) { echo("<br><br><br><center>Sorry,all the fields must be filled out.</center>"); } else { $body1 ="Name : ".$txtFirstName." ".$surname." Address : ".$txtAddress1." ".$txtAddress2." Postal code : ". $postcode." country : ".$txtCountry." Telephone : ".$txtTelephone." Mobile phone : ".$txtMobile." Email: ".$txtEmail." Chosen product :". $txtproduct." ".$brochure." Preffered contact : ".$radContactby; $to = "smnfowler@aol.co.uk"; $subject ="CentreofAttention"; $body = $body1; if (mail($to, $subject, $body)) { echo("<br><br><center>Thank you!Email sent!</center>"); } else { echo("<br><br><br>Message delivery failed...</p>"); } } ?> your help will be much appreciated Flowster if you need to see the form it is at www.centreofattentionuk.com Quote Link to comment https://forums.phpfreaks.com/topic/68606-need-some-help-for-my-form/ Share on other sites More sharing options...
wildteen88 Posted September 9, 2007 Share Posted September 9, 2007 Check against the $_POST variables themselves. Eg: if(!empty($_POST["txtFirstName"]) || !empty($_POST["surname"]) || !empty($_POST["txtAddress1"]) || !empty($_POST["txtAddress2"]) || !empty($_POST["postcode"]) || !empty($_POST["txtCountry"]) || !empty($_POST["txtTelephone"]) || !empty($_POST["txtMobile"]) || !empty($_POST["txtEmail"]) || !empty($_POST["txtproduct"]) || !empty($_POST["brochure"]) || !empty($_POST["radContactby"])) { $txtFirstName=$_POST["txtFirstName"]; $surname=$_POST["surname"]; $txtAddress1=$_POST["txtAddress1"]; $txtAddress2=$_POST["txtAddress2"]; $postcode=$_POST["postcode"]; $txtCountry=$_POST["txtCountry"]; $txtTelephone=$_POST["txtTelephone"]; $txtMobile=$_POST["txtMobile"]; $txtEmail=$_POST["txtEmail"]; $txtproduct=$_POST["txtproduct"]; $brochure=$_POST["brochure"]; $radContactby=$_POST["radContactby"]; Quote Link to comment https://forums.phpfreaks.com/topic/68606-need-some-help-for-my-form/#findComment-344856 Share on other sites More sharing options...
flowster Posted September 9, 2007 Author Share Posted September 9, 2007 all seems fine, still not working. im so frustrated..... Quote Link to comment https://forums.phpfreaks.com/topic/68606-need-some-help-for-my-form/#findComment-344857 Share on other sites More sharing options...
wildteen88 Posted September 9, 2007 Share Posted September 9, 2007 Try the following instead: <?php $fields = array( 'txtFirstName', 'surname', 'txtAddress1', 'txtAddress2', 'postcode', 'txtCountry', 'txtTelephone', 'txtMobile', 'txtEmail', 'txtproduct', 'brochure', 'radContactby' ); $errors = null; foreach($fields as $field) { if(!isset($_POST[$field]) || empty($_POST[$field])) { $errors++; } } if($errors > 0 && !is_null($errors)) { echo '<center>Sorry, all the fields must be filled out.</center>'; } else { $txtFirstName = $_POST["txtFirstName"]; $surname = $_POST["surname"]; $txtAddress1 = $_POST["txtAddress1"]; $txtAddress2 = $_POST["txtAddress2"]; $postcode = $_POST["postcode"]; $txtCountry = $_POST["txtCountry"]; $txtTelephone = $_POST["txtTelephone"]; $txtMobile = $_POST["txtMobile"]; $txtEmail = $_POST["txtEmail"]; $txtproduct = $_POST["txtproduct"]; $brochure = $_POST["brochure"]; $radContactby = $_POST["radContactby"]; // rest of your code here } ?> Quote Link to comment https://forums.phpfreaks.com/topic/68606-need-some-help-for-my-form/#findComment-344863 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.