473,322 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Form Validation

I understand how to validate form data when a form is submitted to
'self' (ie. action="$_SERVER_[PHP_SELF]"). In this case you simply
validate before processing. However, what if submitting the form to
another page (ie. action="someotherpage.php"). You could validate the
form data on the new page but it makes more sense to validate first
before submitting, plus if there are errors, then you have to send the
user back to the first page. There must be a way to do the error
checking before the submit. The only way I can think to do this is with
Javascript and a button element onclick event (instead of Submit button)
with the Javascript handling the form validation and form submit. There
is probably a real obvious PHP solution but I can't see it.
Jul 17 '05 #1
11 2969
peebrain <pb@anon.com> wrote:
There must be a way to do the error checking before the submit. The
only way I can think to do this is with Javascript and a button
element onclick event (instead of Submit button) with the Javascript
handling the form validation and form submit. There is probably a real
obvious PHP solution but I can't see it.


It's very obvious that there is _NO_ way to validate with PHP before
submitting it since PHP is serverside and to get the data from
clientside to serverside it has to be submitted (one way or the other).

Validation needs to be done serverside always, any checks clientside are
a bonus but are not to be relied on.

Jul 17 '05 #2
Daniel Tryba wrote:
peebrain <pb@anon.com> wrote:
There must be a way to do the error checking before the submit. The

It's very obvious that there is _NO_ way to validate with PHP before
submitting it since PHP is serverside and to get the data from
clientside to serverside it has to be submitted (one way or the other).

Validation needs to be done serverside always, any checks clientside are
a bonus but are not to be relied on.


Thanx for the prompt response Daniel. Ok, that makes sense of course. So
clearly I can do some client-side validation with JavaScript but should
also being doing it on the server-side. My problem though is if form
validation fails on "page 2.php" (where the form data was submitted and
the validation performed), how do I return the user to "page1.php" to
try again?
Jul 17 '05 #3


peebrain wrote:

Thanx for the prompt response Daniel. Ok, that makes sense of course. So
clearly I can do some client-side validation with JavaScript but should
also being doing it on the server-side. My problem though is if form
validation fails on "page 2.php" (where the form data was submitted and
the validation performed), how do I return the user to "page1.php" to
try again?


Why do you need separate scripts?

To answer your question, you use the header() function.
www.php.net/header

Ken

Jul 17 '05 #4
I noticed that Message-ID: <bJ0ve.98809$on1.49016@clgrps13> from
peebrain contained the following:
My problem though is if form
validation fails on "page 2.php" (where the form data was submitted and
the validation performed), how do I return the user to "page1.php" to
try again?


You could always tell them to press the back button.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #5
On Sat, 25 Jun 2005 00:43:29 +0100, Geoff Berrow
<bl******@ckdog.co.uk> wrote:
I noticed that Message-ID: <bJ0ve.98809$on1.49016@clgrps13> from
peebrain contained the following:
My problem though is if form
validation fails on "page 2.php" (where the form data was submitted and
the validation performed), how do I return the user to "page1.php" to
try again?


You could always tell them to press the back button.


Or:

if (whatever determines failure) {

echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0 ;URL=\"page1.php\">";
echo $Refresh;

}
--
gburnore@databasix dot com
---------------------------------------------------------------------------
How you look depends on where you go.
---------------------------------------------------------------------------
Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³Ýۺݳ޳ºÝ³Ý³Þ³ºÝ³ÝÝÛ³
| ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
Black Helicopter Repair Svcs Division | Official Proof of Purchase
================================================== =========================
Want one? GET one! http://signup.databasix.com
================================================== =========================
Jul 17 '05 #6
Geoff Berrow <bl******@ckdog.co.uk> wrote:
My problem though is if form
validation fails on "page 2.php" (where the form data was submitted and
the validation performed), how do I return the user to "page1.php" to
try again?


You could always tell them to press the back button.


How very userfriendly. Server decides that something is wrong and that
the user should fix it by themselves by backing up a few pages. Some
problems it cause:
-what was wrong again?
-password fields tend to be empty in some browsers (good thing (tm))
-other fields may be reset to defaults (eg. select)

Jul 17 '05 #7
Ken Robinson wrote:

peebrain wrote:

... My problem though is if form
validation fails on "page 2.php" (where the form data was submitted and
the validation performed), how do I return the user to "page1.php" to
try again?

Why do you need separate scripts?

To answer your question, you use the header() function.
www.php.net/header

Ken


Good one Ken. That will be very useful if not in this case then in other
situations where I want to redirect to another page.
8< --------------
header("Location: http://www.example.com/"); /* Redirect browser */
8< --------------
thanx.
The reason for two pages is that the data submitted by the first form
gets loaded up into a different form. This could all be done in one
script but logically made sense to two separate purpose scripts.
Jul 17 '05 #8
Gary L. Burnore wrote:
On Sat, 25 Jun 2005 00:43:29 +0100, Geoff Berrow
<bl******@ckdog.co.uk> wrote:

I noticed that Message-ID: <bJ0ve.98809$on1.49016@clgrps13> from
peebrain contained the following:

My problem though is if form
validation fails on "page 2.php" (where the form data was submitted and
the validation performed), how do I return the user to "page1.php" to
try again?


You could always tell them to press the back button.

Or:

if (whatever determines failure) {

echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0 ;URL=\"page1.php\">";
echo $Refresh;

}


This is also a good one. Thanx Gary. This or the header() function
mentioned by Ken will both accomplish the redirect.
Jul 17 '05 #9
Hello,

on 06/24/2005 07:51 PM peebrain said the following:
I understand how to validate form data when a form is submitted to
'self' (ie. action="$_SERVER_[PHP_SELF]"). In this case you simply
validate before processing. However, what if submitting the form to
another page (ie. action="someotherpage.php"). You could validate the
form data on the new page but it makes more sense to validate first
before submitting, plus if there are errors, then you have to send the
user back to the first page. There must be a way to do the error
checking before the submit. The only way I can think to do this is with
Javascript and a button element onclick event (instead of Submit button)
with the Javascript handling the form validation and form submit. There
is probably a real obvious PHP solution but I can't see it.


You may want to try this class that performs both client side
(Javascript) and server side (PHP) validation from the same set of rules.

http://www.phpclasses.org/formsgeneration
--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #10
Following on from Daniel Tryba's message. . .
Geoff Berrow <bl******@ckdog.co.uk> wrote:
My problem though is if form
validation fails on "page 2.php" (where the form data was submitted and
the validation performed), how do I return the user to "page1.php" to
try again?


You could always tell them to press the back button.


How very userfriendly. Server decides that something is wrong and that
the user should fix it by themselves by backing up a few pages. Some
problems it cause:
-what was wrong again?
-password fields tend to be empty in some browsers (good thing (tm))
-other fields may be reset to defaults (eg. select)

Quite agree 90% of time, as if there is _no decision_ to be made by the
user except to type in the damn thing correctly then the suitable page
should be displayed automatically there and then with _informative,
unambiguous and well-positioned error message_.

However there are situations where the 'error' is not a matter of sloppy
input but logic known to the system only. For example : "You have
ordered two sweets but no main course do you really want to do this?".
In this case 'back' is a logical option in the minds of some users. I
would _not_ expect or encourage users to use Back (or forward) buttons
and therefore provide proper yes and no buttons on the screen to do this
*but* some users will use the Back button regardless and so your screen
logic needs to be able to cope with this 'mis-use'.


--
PETER FOX Not the same since the bottom fell out of the bucket business
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Jul 17 '05 #11
I noticed that Message-ID: <42***********************@news6.xs4all.nl>
from Daniel Tryba contained the following:
You could always tell them to press the back button.


How very userfriendly. Server decides that something is wrong and that
the user should fix it by themselves by backing up a few pages.


Please note I said /could/. I'll admit it's a quick and dirty solution
(though I use it in my mail script where the originating page is bog
standard html with no php).

Using some kind of redirect will involve passing the input back to the
form. Which means page 1 has to have the capacity to redisplay them.
And if you are going to do that you may as well build in the validation
into page 1 and simply redirect to a thank you page on success.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Phil Powell | last post by:
Where can I find an online PHP form validator script library to use? I have tried hacking the one here at work for weeks now and it's getting more and more impossible to customize, especially now...
4
by: TG | last post by:
I have a validation form that must behave differently based on the results of a PHP validation check. I have a post command at the top of my form that calls itself. I don't leave the form when...
4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
16
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.