DWilliams Posted April 29, 2010 Share Posted April 29, 2010 For example, say I'm making a simple registration form. My initial input form submits to the same page via POST. After submitting, my page does all the usual input validation. Now, instead of a "correct and resubmit", what if I only want to warn the user that what they entered may not be correct and give them a "yes I'm sure" button? In my error section, can I have a form like the following: <form action="mypage.php" method="post"> <input type="hidden" name="override" value="1" /> <input type="submit" value="Yes I'm sure" /> </form> When the user clicks the button on that form, will the $_POST array I have access to (with name, email, etc etc) currently be available to my script after THIS form is submitted or do I have to manually re-add each value to the form like so: <form action="mypage.php" method="post"> <input type="hidden" name="override" value="1" /> <input type="hidden" name="username" value="{$_POST['username']}" /> <input type="hidden" name="email" value="{$_POST['email']}" /> // And so on... <input type="submit" value="Yes I'm sure" /> </form> Link to comment https://forums.phpfreaks.com/topic/200180-does-post-data-clear-between-pages/ Share on other sites More sharing options...
mrMarcus Posted April 29, 2010 Share Posted April 29, 2010 manually re-enter Link to comment https://forums.phpfreaks.com/topic/200180-does-post-data-clear-between-pages/#findComment-1050580 Share on other sites More sharing options...
conker87 Posted April 29, 2010 Share Posted April 29, 2010 Use sessions. session_start(); $_SESSION['username'] = $_POST['username']; Etc. Link to comment https://forums.phpfreaks.com/topic/200180-does-post-data-clear-between-pages/#findComment-1050593 Share on other sites More sharing options...
DWilliams Posted April 29, 2010 Author Share Posted April 29, 2010 manually re-enter Hmm that's unfortunate. I guess I could make some function like function PostToHiddenField($postarray) { foreach(array_keys($postarray) as $item) echo "<input type=\"hidden\" name=\"$item\" value=\"{$postarray[$item]}\" />"; } I'm sure there's some built-in way to handle it with PHP though... Link to comment https://forums.phpfreaks.com/topic/200180-does-post-data-clear-between-pages/#findComment-1050597 Share on other sites More sharing options...
DWilliams Posted April 29, 2010 Author Share Posted April 29, 2010 Use sessions. session_start(); $_SESSION['username'] = $_POST['username']; Etc. But then wouldn't that require a user to have cookies enabled? I like to keep my code as browser-independent as possible Link to comment https://forums.phpfreaks.com/topic/200180-does-post-data-clear-between-pages/#findComment-1050599 Share on other sites More sharing options...
ignace Posted April 29, 2010 Share Posted April 29, 2010 I like to keep my code as browser-independent as possible Cookies are supported by most (if not all) browsers. Your function will do fine although I would recommend generalizing it more, like: function htmlInput($array, $type = 'hidden') { $html = ''; foreach($array as $name => $value) $html .= "<input type=\"$type\" name=\"$name\" value=\"$value\" />\r\n"; return $html; } Link to comment https://forums.phpfreaks.com/topic/200180-does-post-data-clear-between-pages/#findComment-1050623 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.