/    Sign up×
Community /Pin to ProfileBookmark

Advice regarding form data

Hello!

I am after a bit of advice please. I am trying to improve the method I have for dealing with invalid submissions, and retaining the $_POST data to repopulate a form when navigated back to it

Currently, I have only done this for <input’s and I know I need to implement the same for <select’s, but thought I would check this method and get any improvements before I do that (there’s tonnes…!)

At the moment, I have the following:

form.php:

[code=php]
all the rest of the form…
<input type=”text” name=”NAME” class=”formwidth” maxlength=”32″ value=”<?php echo $_SESSION[‘supportname’]; ?>” />
[/code]

this “form.php” submits to my “support.php”, which contains:

[code=php]
$_SESSION[‘supportname’] = htmlentities($_POST[‘NAME’]);

// validation
// if all ok, unset() it
[/code]

1) Would you suggest not posting to a different page, instead should I submit to the same page?
2) I’d like to display my validation errors, and show the form repopulated beneath it – how can I do that?
3) I’d like to insert a little “red” attention sign to all the failed inputs… is that easy?

Thanks in advance for any advice you can provide

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@furnissgJun 25.2008 — i would suggest you post to the same page its easier to repopulate the form and i think easier for validation.

You can validate the form then if it is valid move onto the next page.

repopulate the form with something like

[code=php]

<input type="text" name="NAME" class="formwidth" maxlength="32" value="<?php if(isset($_POST['NAME'])) echo $_POST['NAME']; ?>" />
[/code]


if you set the validation errors the little red attention is easy just use something like

[code=php]

if(isset($error['name'])){

echo '<p style="color:red">Errror Message</p>';

}

[/code]
Copy linkTweet thisAlerts:
@DanUKauthorJul 02.2008 — Thanks for that, I'll look into it

Sorry for the slow reply back ?
×

Success!

Help @DanUK 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.17,
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,
)...