Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/68606-need-some-help-for-my-form/
Share on other sites

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"];

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
}

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.