Jump to content

How is the best way to submit a form?


johnsmith153

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.

 

 

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.