/    Sign up×
Community /Pin to ProfileBookmark

Contact Form Help

Ok, I fixed my last problem, but there’s one thing I don’t understand now.

I have contact.htm going to mailer.php… do I make the php page the “Your message has been sent” page? How do I redirect the person back to the form with all the values still in the fields if the PHP validation is wrong?

I am using JavaScript and I want to use PHP validation too.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@chesemonkylomaSep 13.2006 — The "message has been sent" [I]will[/I] be the PHP page.

What I would suggest is having the form submit to itself. Here's some small example code:
[code=php]
<?php
if (isset("$_POST['submit']" AND it validates){ /*I'm not good with validation code and regex so I'm not completely sure how that would be done*/
echo "blah blah blah success!"; //tell them it worked
}
else{
if (it doesn't validate (insert code or whatever there) ) { //more validation
echo "Your values are not correct";
} ?>
<FORM action="$_SERVER['PHP_SELF']" method="post">//submits to itself
<input type="text" name="poopoo" value="<?php echo "$_POST['poopoo']"> //if post hasn't been "posted" it will still work fine
<input type="submit" name="submit" value="Submit">//submit
</FORM>
}
Copy linkTweet thisAlerts:
@Reli4ntSep 13.2006 — I completely agree. I find it much easier to keep my scripts in one, file. It's faster, and much more versatile.

To amend the above I would put [CODE]value="<?php echo (isset($_POST['poopoo']))?$_POST['poopoo']:'' ;?>"[/CODE]
This way you don't get an warning when error reporting is on all.
×

Success!

Help @Mig 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 5.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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...