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:

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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