/    Sign up×
Community /Pin to ProfileBookmark

form validation: go back to partly-filled form

Hi Gurus

If one input has data and another doesn’t, I want to ‘redirect’ back to the form. The code I know about is

[code=php]if (($_POST[‘eletter’]==-1) and (!$_POST[‘EAddress’])) {
echo “<meta http-equiv=”refresh” Content=”0;URL=signup.php”>”;
exit(‘Email address is required if you want to receive email updates…’);
}[/code]

but it reloads the page. I want to just go back in history, so that the data they entered is still there…

I was thinking about just printing a message on the page that processes the form, that says to hit the Back button to fill in the missing data, but I don’t know if I like that. Recommendations?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@crh3675Mar 16.2006 — [code=php]

if (($_POST['eletter']==-1) and (!$_POST['EAddress'])) {
exit("Email address is required if you want to receive email updates...<script type="text/javascript">setTimeout("window.history.go(-1)",2000);</script>");
}
[/code]
Copy linkTweet thisAlerts:
@SheldonMar 16.2006 — or use sessions

to store the post data and then to populate the form feilds if you need to go back.

Making a multi page form easy, and when the form is submitted/finished use session unset to delete all the sessions that you set during submitting the form.

You also can leave one sesion var set to check for before submitting the form to stop multiple submissions
Copy linkTweet thisAlerts:
@strBeanauthorMar 16.2006 — Thanks for the ideas.

I've started reworking this, and I'm using Sheldon's idea. The approach I'm taking is to use an include file, to keep the code on my main page a little simpler.

Question: When I require a file in a page that already has session_start() at the top of it, I'm assuming the $_SESSION array values are available to the code in the include file too, right?
×

Success!

Help @strBean spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...