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> Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 29, 2010 Share Posted April 29, 2010 manually re-enter Quote Link to comment 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. Quote Link to comment 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... Quote Link to comment 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 Quote Link to comment 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; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.