PHP after form submission disappears instead of redirecting via header location

user3524234

Cannot redirect form after submission. Form simply disappears from page and the page stays the same.

Any input is welcomed. Using Twitter Bootstrap, GoDaddy hosting (I know).

FORM:

<div class="row">
    <div class="col-lg-7 col-lg-offset-3">
        <form class="well" role="form" id="colform" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
            <div class="row">
                <div class="col-lg-3 pull-left error">
                    <p class="text-left">* - Required Fields</p>
                </div>
            </div>
            <div class="row">
                <div class="form-group col-sm-4">
                    <label class="control-label" for="name">Your Name *</label>
                    <input type="text" class="form-control" name="name">
                    <span class="help-block error"><?php echo $nameErr;?></span>
                </div>
                <div class="form-group col-sm-4">
                    <label class="control-label" for="phone_number">Phone Number *</label>
                    <input type="text" class="form-control" name="phone_number">
                    <span class="help-block error"><?php echo $phone_numberErr;?></span>
                </div>
                <div class="form-group col-sm-4">
                    <label class="control-label" for="email">Email</label>
                    <input type="text" class="form-control" name="email">
                    <span class="help-block error"><?php echo $emailErr;?></span>
                </div>
            </div>

            <div class="row">
                <div class="form-group col-sm-4">
                    <label class="control-label" for="city">City *</label>
                    <input type="text" class="form-control" name="city">
                    <span class="help-block error"><?php echo $cityErr;?></span>
                </div>
                <div class="form-group col-sm-4">
                    <label class="control-label" for="post_code">Post Code *</label>
                    <input type="text" class="form-control" name="post_code">
                    <span class="help-block error"><?php echo $post_codeErr;?></span>
                </div>
                <div class="form-group col-sm-4">
                    <label class="control-label" for="full_address">Full Address *</label>
                    <input type="text" class="form-control" name="full_address">
                    <span class="help-block error"><?php echo $full_addressErr;?></span>
                </div>
            </div>

            <div class="form-group row">
                <div class="input-group col-md-6 col-md-offset-3">
                    <span class="input-group-addon">Quantity of bags you have: *</span>
                    <input type="text" class="form-control" name="bags">
                </div>
            </div>

            <div class="row form-group">
                <div class="col-sm-10 col-sm-offset-1">
                    <label class="" >&nbsp; &nbsp;Please leave any additional information you would think is important to mention:</label>
                    <textarea class="form-control" rows="3" name="comments"></textarea>
                </div>
            </div>

            <div class="row form-group">
                <div class="col-sm-10 col-sm-offset-1">
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" name="updates"> If you would like to receive news and updates on our services, please thick this box
                        </label>
                    </div>
                </div>
            </div>

            <div class="alert alert-danger"><span class="label label-danger">IMPORTANT !</span> &nbsp; &nbsp;
                Each item in the bag is checked, please make sure that it doesn't contain following items: </br></br>
                <div class="text-center"><strong>wet, dirty, ripped, bad quality or old fashioned clothing(90s, 80s or older).</br>
                    underwear, school uniform, work clothes.</strong></div></br>

                <div class="text-center small">It will save your precious time and prevent any inconvenience that might occur during the process, which we always try to make no longer than 10-12mins no matter the quantity.</br>
                    Can't check everything or not sure what's inside the bags?</br> Not a problem at all, just make a note of that in the comment box above.
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6 col-sm-offset-3">
                    <button type="submit" class="btn btn-primary btn-lg btn-block" name="fsubmit" >Send Request</button>
                </div>
            </div>

        </form>
    </div>
</div>

PHP CODE IS JUST ABOVE THIS HTML:

<?php
// define variables and set to empty values
$nameErr = $emailErr = $cityErr = $post_codeErr = $full_addressErr = $phone_numberErr = "";
$name = $email = $city = $comment = $post_code = $full_address = $phone_number = $bags = "";
$nameCheck = $cityCheck = $post_codeCheck = $full_addressCheck = $phone_numberCheck = $emailCheck = false;

if ($_SERVER["REQUEST_METHOD"] == "POST")
{
    /*  CHEKING NAME FIELD  */
    if (empty($_POST["name"]))
       { $nameErr = "Name is required"; }
    else {
          $name = test_input($_POST["name"]);
          if (!preg_match("/^[a-zA-Z ]*$/",$name))
             { $nameErr = "Only letters and white space allowed"; }
          else
               { $nameCheck=true; }
         }

    /*  CHECKING CITY FIELD */
    if (empty($_POST["city"]))
       { $cityErr = "City is required"; }
    else {
          $city = test_input($_POST["city"]);
          if (!preg_match("/^[a-zA-Z ]*$/",$city))
             { $cityErr = "Only letters and white space allowed"; }
          else
               { $cityCheck=true; }
         }

    /* CHECKING POST CODE FIELD*/
    if (empty($_POST["post_code"]))
       { $post_codeErr = "Post Code is required"; }
    else {
          $post_code = test_input($_POST["post_code"]);
          if (!preg_match("/^[a-zA-Z \d]*$/",$post_code))
             { $post_codeErr = "Only letters, whole numbers and white space allowed"; }
          else
               { $post_codeCheck=true; }
         }

    /* CHECKING FULL ADDRESS FIELD */
    if (empty($_POST["full_address"]))
       { $full_addressErr = "Full address is required"; }
    else {
          $full_address = test_input($_POST["full_address"]);
          if (!preg_match("/^[a-zA-Z \d,.]*$/",$full_address))
             { $full_addressErr = "Only letters, whole numbers, commas, dot and white space allowed"; }
          else
               { $full_addressCheck=true; }
         }

    /* CHECKING PHONE FIELD */
    if (empty($_POST["phone_number"]))
       { $phone_numberErr = "Phone number is required"; }
    else {
          $phone_number = test_input($_POST["phone_number"]);
          if (!preg_match("/^[ \d]*$/",$phone_number))
             { $phone_numberErr = "Only whole numbers and white space allowed"; }
          else
               { $phone_numberCheck=true; }
         } 

    /* CHECKING BAG FIELD */
    if (empty($_POST["bags"]))
       { $bags = ""; }
    else
         { $bags = test_input($_POST["bags"]); }

     /* CHECKING EMAIL FIELD */
     if (empty($_POST["email"]))
        { $email = "No email entered";
          $emailCheck=true; }
     else {
           $email = test_input($_POST["email"]);
           if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
              { $emailErr = "Invalid email format"; }
           else
                { $emailCheck=true; }
           }

    /* CHECKING COMMENTS FIELD */
    if (empty($_POST["comment"]))
       { $comment = ""; }
    else
         { $comment = test_input($_POST["comment"]); }

    if ($nameCheck && $cityCheck && $post_codeCheck && $full_addressCheck && $phone_numberCheck && $emailCheck)
       { $email = $_POST['email'] ;
         $subject = date("d.M H:i") ;
         $message = "Name:  " . $_POST['name'] . "\n" . "City:  " . $_POST['city'] . "\n" . "Post Code:  " . $_POST['post_code'] . "\n" . "Full Address: " . $_POST['full_address'] . "\n" . "Phone Number: " . $_POST["phone_number"] . "\n" . "Email: " . $_POST["email"] . "\n" . "Number of bags: " . $_POST["bags"] . "\n" . "Comments: " . $_POST["comments"] . "\n" . "Would like to receive updates: " . $_POST['updates'];
         mail("[email protected]", "$subject", $message, "From:" . $email); /* Send Email */
         header("Location: http://www.google.com");
         exit();
        }
}

function test_input($data)
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}               

?>

phpniki

You need to use header in the top of your code without any output on page.

for example if you use a code like this it's not work correctly:

echo "hi";
header("location: http://www.google.com");

you can't output any data before header command.

you should try to change your code positions

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

php form submission is working but erroring instead of redirecting

From Dev

header location not redirecting after form submit

From Dev

header() redirects page automatically instead of after submission of form

From Dev

redirecting to another page after form submission

From Dev

header location error redirecting

From Dev

php return to page after form submission

From Dev

Run PHP Code After Form Submission And Redirect

From Dev

php return to page after form submission

From Dev

Keeping values selected after form submission with php

From Dev

Run script and php after form submission

From Dev

Child refreshing self instead of parent after form submission Javascript

From Dev

Send Email after form submission via email service such as Mailchimp

From Dev

Clear the form field after successful submission of php form

From Dev

Redirecting by Header in php

From Dev

php get location header after post request

From Dev

Contact form not sending full submission data via php

From Dev

Why do I see a blank screen after form submission in PHP?

From Dev

How to show a success message after PHP form submission?

From Dev

Keep form data inside the field after submission using php

From Dev

how to clear form using php PDO after successful submission

From Dev

jquery ajax requests are not responding on the new tab after the php form submission

From Dev

Can't get rid of blank php page after submission form

From Dev

AJAX and php form inadvertently refreshes again after submission

From Dev

Form in html is not redirecting to php

From Dev

Form in html is not redirecting to php

From Dev

Form Submission to Self (PHP)

From Dev

PHP contact form submission

From Dev

PHP, email submission form

From Dev

UICollectionView header title disappears after

Related Related

  1. 1

    php form submission is working but erroring instead of redirecting

  2. 2

    header location not redirecting after form submit

  3. 3

    header() redirects page automatically instead of after submission of form

  4. 4

    redirecting to another page after form submission

  5. 5

    header location error redirecting

  6. 6

    php return to page after form submission

  7. 7

    Run PHP Code After Form Submission And Redirect

  8. 8

    php return to page after form submission

  9. 9

    Keeping values selected after form submission with php

  10. 10

    Run script and php after form submission

  11. 11

    Child refreshing self instead of parent after form submission Javascript

  12. 12

    Send Email after form submission via email service such as Mailchimp

  13. 13

    Clear the form field after successful submission of php form

  14. 14

    Redirecting by Header in php

  15. 15

    php get location header after post request

  16. 16

    Contact form not sending full submission data via php

  17. 17

    Why do I see a blank screen after form submission in PHP?

  18. 18

    How to show a success message after PHP form submission?

  19. 19

    Keep form data inside the field after submission using php

  20. 20

    how to clear form using php PDO after successful submission

  21. 21

    jquery ajax requests are not responding on the new tab after the php form submission

  22. 22

    Can't get rid of blank php page after submission form

  23. 23

    AJAX and php form inadvertently refreshes again after submission

  24. 24

    Form in html is not redirecting to php

  25. 25

    Form in html is not redirecting to php

  26. 26

    Form Submission to Self (PHP)

  27. 27

    PHP contact form submission

  28. 28

    PHP, email submission form

  29. 29

    UICollectionView header title disappears after

HotTag

Archive