June 4, 200818 yr So I have a form that submits user supplied data which is then checked for a few things and (if successful) added to the database. The form submits to itself and sets a "submitted" value to 1, so that when the page reloads, it gets caught by the "if($_POST['submitted']))". The only problem is that if something goes wrong with the users input (they forget to fill in a field) the error message will be displayed, they will click "Back" and all of the information they put in is gone! For example, this is how I check the data: if (empty($_POST['artist']) || empty($_POST['description'])) { echo "Oops! Looks like you haven't filled in all of the fields. Go back and try again."; } Then they click on Back and it's all blank. I know this is going to be very frustrating if it happens to anyone as they are inputting reviews and a lot of formatting so they will not be happy if they have to do it again! How can I fix this problem? Thanks!
June 4, 200818 yr Hi Garry, I think what you're after is 'sticky' form fields. For example, if you had an input field to capture a first name, have something like this: <input id="first_name" name="first_name" class="text" type="text" size="20" maxlength="40" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /> I hope that is what you mean. See my contact page for an example. Only fill in some of the fields and submit the form.
June 5, 200818 yr ^ Going from this, sanitise it first! Don't ever echo unsanitised user input back to the browser.
June 8, 200818 yr Author Finally got it working! What I needed to do was use an $errors array and have the form in a function which can be recalled if an error occured. Thanks for everyones help
Create an account or sign in to comment