Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Web Design (WordPress, Joomla, etc.) Validating a multi page sessions form with php

  • Validating a multi page sessions form with php

    Posted by Travis Barr on January 1, 2011 at 7:30 pm

    I have tried every way but the correct way to figure this one out. I have a multi page sessions form and I have an inline validation script. I am trying to figure out how to combine the two. For the sake of saving space I will not post all my mistakes, but bellow are the two scripts. Any advice or pointers would be welcomed, thanks.

    Multi form script:

    <?php

    //Turn on sessions
    session_start();

    //Find what stage to use
    if (($_SERVER['REQUEST_METHOD'] == 'GET') || (!isset($_POST['stage'])))
    {
    $stage = 1;
    }
    else
    {
    $stage = (int) $_POST['stage'];
    }

    // Save any submitted data
    if ($stage > 1)
    {
    foreach ($_POST as $key => $value)
    {
    $_SESSION[$key] = $value;
    }
    }
    if ($stage == 1)
    {

    ?>

    ################################
    ################################
    ################################

    The validation script:

    <?php

    if ($_SERVER['REQUEST_METHOD'] == 'GET')
    {

    //just display the form if the request is GET
    display_form(array());
    }
    else
    {
    //the request is a POST so validate the form
    $errors = validate_form();
    if (count($errors))
    {
    //if there were any errors, redisplay the form with the errors
    display_form($errors);
    }
    else
    {
    //the form data was valid so print a congratulations message
    print 'the form was submitted.';
    }
    }

    function display_form($errors)
    {
    //set up defaults
    $defaults['first_name'] = isset($_POST['first_name']) ? htmlentities($_POST['first_name']) : '';

    ?>

    Travis Barr replied 15 years, 8 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy