Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Keeping POST data if an error occurs

Featured Replies

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!

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. :)

^ Going from this, sanitise it first! Don't ever echo unsanitised user input back to the browser.

  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.