Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

How can I get a form to redirect once all validation has been met ?

Hello

How can I get a form to redirect once all validation has been met and also carry the information from the form along to the new page ?

Kyle Robertson
Kyle Robertson
31,600 Points

You can use the header() function after validation has been completed.

header('Location: redirect.php');
exit();

EDIT: You can send the form data in a $SESSION store.

form.php

session_start();

if ($_POST['submitted']) {
    if ($no_error) {
        $_SESSION['form_data'] = $_POST;
        header ("Location: redirect.php"); 
        exit();
    }
}

redirect.php

session_start();

if ($_SESSION['form_data']) {
    # do your thing here
}