Jump to content

PHP error checking forms and redirection


jbradley04

Recommended Posts

Hello all!

I have a question...

I have a form in which I am doing the error checks server side with PHP...

So if they submit this form and they forget a field, it redirects them back to the original form and an erro message pops up...

The problem is every time they get redirected back to original form they have to enter all the information back in! 

Is there a way to pass these posted variables back to original form?

I hope this makes sense!

Thanks for your help!

:confused:

Here's a basic example:

 

<?php

// Start the session.
session_start();

$data    = $_POST; 

if(isset($data['submit']) && !empty($data['submit'])) {

   // Set the posted data to a unique key in the global session data array.
   $_SESSION['posted_values'] = $data;
}

?>

<!--// 
   Input fields shown how to set the value from the session and then the submit button to go along with my form check above.
//-->

<form>
   <input type="text" name="email" value="<?= isset($_SESSION['posted_values']['email']) && !empty($_SESSION['posted_values']['email'])? $_SESSION['posted_values']['email'] : null; ?>" />
   <input type="submit" value="submit" name="submit" />
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.