1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Empty $_POST on form submission?

Discussion in 'PHP & Perl' started by Moobs, Jun 15, 2015.

Tags:
  1. Moobs

    Moobs Regular Member

    Joined:
    Jan 30, 2015
    Messages:
    238
    Likes Received:
    14
    I created a simple birthday calculator that allows a user to submit their birthday, and then a bunch of facts relative to that date gets spit out. Everything works as intended in chrome, but not in firefox or safari. I'm not receiving any errors. The page gets redirected as it should when the form is submitted, but the form data is be placed into the $_POST array and then set to a session variable as it should. I have other forms on my site that work with all browsers, so I'm not sure where I've gone wrong.

    This is how I'm passing the $_POST data to $_SESSION:


    PHP:
    session_start();error_reporting(E_ALL); ini_set('display_errors',1);


    if(
    count($_POST) > 0) {
            
    $_SESSION['dob-month'] = $_POST['dob-month'];
    $_SESSION['dob-day'] = $_POST['dob-day'];
    $_SESSION['dob-year'] = $_POST['dob-year'];


    if(isset(
    $_POST['submit'])){
    $_SESSION['submit'] = 1;}


    header("HTTP/1.1 303 See Other");
    header("Location: https://$_SERVER[HTTP_HOST]/calculator/");
            die();
        }
    elseif (isset(
    $_SESSION['dob-month'])||isset($_SESSION['dob-day'])||isset($_SESSION['dob-year'])){
            
    $month $_SESSION['dob-month'];
    $day ltrim(sanitizeNumInput($_SESSION['dob-day']),'0');


    $year sanitizeNumInput($_SESSION['dob-year']);
    $submit $_SESSION['submit'];


            
    /*
                Put database-affecting code here.
            */




            
    session_unset();
            
    session_destroy();
        }else{
    $month null;
    $day null;
    $year null

    Here's how I'm creating the form:

    PHP:
    echo '
    <div class="calc-holder">
    <form method="post" action="/calculator/"> 


    <div class="dobRow">
    <div class="dobMonth">
    <select name="dob-month">
    '
    .$monthOptions;


    while(
    $i <= 12){
    foreach(
    $monthList as $key => $val){
    if(
    $i != $month){
    echo 
    '<option value="'.$key.'">'.$val.'</option>';}
    $i++;
    }
    }


    echo 
    '


    </select>
    </div><!--end dobMonth-->
    <div class="dobDay"><input type="text" name="dob-day" maxlength="2" '
    .$dayHolder.'/></div><!--end dobDay-->
    <div class="dobYear"><input type="text" maxlength="4" max="'
    .date('Y').'" name="dob-year" '.$yearHolder.'/></div><!--end dobYear--> 
    <div class="dobSubmit"><input type="submit" name="submit" value="Calculate"/></div><!--end dobSubmit-->
    </div><!--end dobRow-->




    </form>
    </div><!--end calc-holder-->'
    ;
    I've been struggling with this all day, any help would be greatly appreciated.
     
    Last edited: Jun 15, 2015
  2. Moobs

    Moobs Regular Member

    Joined:
    Jan 30, 2015
    Messages:
    238
    Likes Received:
    14
    I cannot for the life of me figure out why a 303 redirect works in Chrome only. I created a post, redirect, get function to handle form data to avoid duplicate submissions if the page is refreshed.
    PHP:
    header("HTTP/1.1 303 See Other");
        
    header("Location: https://$_SERVER[HTTP_HOST]/test-form/");
        die();
    I just don't understand why this doesn't work outside a chrome browser. The end result it produces in firefox and safari is an empty form as if your\'re viewing the page for the first time. The session and post arrays appear to empty once hitting this block in firefox and safari.