Ninjakreborn Posted May 18, 2006 Share Posted May 18, 2006 is this the correct way to repopulate a form field. meaning if it is submitted and validates wrong it leaves in what they already typed, and if they hit refresh is it still suppose to stay there, because right now when I use the code, it doesn't stay where it is supposed to stay when I press refresh.[code]<input tabindex="1" name="firstname" id="firstname" type="text" maxlength="30" value="<?php echo $_POST["firstname"]; ?>" />[/code]I thought that for instance, when someone typed in firstname here, it was recorded, adn then if it was refreshed, or changed screens, or flickered in the server and back out to validate that it would keep that field full of what they had previously typed. Or is this somethign that will work, just not when someone hits the refresh button, if not should I try to come up with a way to keep it from clearing when the refresh button is pressed. Quote Link to comment https://forums.phpfreaks.com/topic/9925-repopulate-form-fields/ Share on other sites More sharing options...
wildteen88 Posted May 18, 2006 Share Posted May 18, 2006 This is normal behavior with refresh. Refrsh clears any POST/GET data currently being transferred to the server/client. Thefore your POST'd data is not available any more. If you want the data that is currently in the form fields then you might want to save any POST'd data into a cookie/session and each time the page is requested put in the saved data into the form fields. Quote Link to comment https://forums.phpfreaks.com/topic/9925-repopulate-form-fields/#findComment-36902 Share on other sites More sharing options...
Ninjakreborn Posted May 18, 2006 Author Share Posted May 18, 2006 Ok so then let me ask this.If I leave that code I showed you above in all my values for text fields, when someone clicks submit, it validates it on the other page, and comes up with the error messages, when they hit the back button will that code keep it in the places they already filled out. The other question was, I have it sent to another page, where it's processing it and emailing it to me. I want to validate it with php too, should i just write up some functions on the form page, and if I do will it automatically run them when I click submit, or do I need to just do it on the other page, what I need is for it to run through all the validation functions, return all the errors, which I can do, but then if it doesn't have any email it, I am worried the ground of validation functions, and the mail functions are going to conflict with each other somehow, any advice. The main thing I need to know is about the repopulation, will that string of code show work like that. Quote Link to comment https://forums.phpfreaks.com/topic/9925-repopulate-form-fields/#findComment-36904 Share on other sites More sharing options...
ober Posted May 18, 2006 Share Posted May 18, 2006 The proper way to do it is to have your validation code on the same page as the form. When the user submits the form it refers back to the same page and if the form results are invalid, you show the form again and the values are already there in the POST/GET. But you do all the validation before any HTML so if the validation is correct, you send the user onto a "thank you" page with the header() call. You can do the mailing after the validation or on the thank you page, it doesn't matter which one. Quote Link to comment https://forums.phpfreaks.com/topic/9925-repopulate-form-fields/#findComment-36934 Share on other sites More sharing options...
Ninjakreborn Posted May 18, 2006 Author Share Posted May 18, 2006 The thing I don't understand is, now that I worked with it, I have the answers completely, it validates and processes on an external page. But I didn't need to do anything with repopulation. When they hit the back button it automatically still has the info in the slots, that is confusing. Quote Link to comment https://forums.phpfreaks.com/topic/9925-repopulate-form-fields/#findComment-36938 Share on other sites More sharing options...
ober Posted May 18, 2006 Share Posted May 18, 2006 That's correct in most cases, but why should your user have to hit the back button??? You should be doing that for them.And at least for IE, you'll often get "Page Expired" errors when you try to go back to a form like that. Quote Link to comment https://forums.phpfreaks.com/topic/9925-repopulate-form-fields/#findComment-36941 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.