Jump to content

Recommended Posts

I submit forms to the same page so I can use value="$_POST['formField']" in the form to display values entred to user if form submit is not fully completed.

 

However, I then get the web page expired problem.

 

If I submit to a different script I then lose $_POST values when I header redirect back to display the form.

 

I suppose the question is "how do I do form submitting where I don't get the web-page expired problem AND I can reuse $_POST values?"

Link to comment
https://forums.phpfreaks.com/topic/208410-how-is-the-best-way-to-submit-a-form/
Share on other sites

Answer:

 

capture on the processing (non form) page:

<?php
session_start();
$_SESSION['postData'] = $_POST;
?>

 

Display on the form page

<?php
session_start();
$postData = $_SESSION['postData'];
?>

<form>
<input type="text" name="name" value="<?php echo $postData['name']; ?>" />
</form>

<?php
unset($_SESSION['postData']);//important so when return to page, form shows blank
?>

I submit forms to the same page so I can use value="$_POST['formField']" in the form to display values entred to user if form submit is not fully completed.

 

However, I then get the web page expired problem.

Was curious what method you were using... as that just means that it just doesn't work. Not why it doesn't work, just that you are using $_POST. This could be for a hundred reasons is all. Would have mattered to get more help was all, was just trying to prod some help for you thought you had a specific issue. Didn't realize you wanted a broad answer.

 

Anyways... to answer your questions:

(a) This shouldn't happen if php is running correctly, this just means the php code did not compile to run correctly and you have error reporting off most likely.

(b) You need checks in place to check if this page is first run and checks for if it is not first run then error checking for blank form fields. Then depending on how you are using the $_POST variables you could dump it at the beginning of the script to a dummy variable if it is causing issues with multiple use, not sure how it will be used but it's a method that could use as well.

 

 

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.