On Friday 20 December 2002 22:25, Mignon Hunter wrote:
> Hello list,
> I am developing a db form that gets passed to another form.  I need to
> validate the fields in form(1), before passing on.  The form action
> posts to form(2), so that upon hitting submit - form(2) shows up in
> browser...(the only way I know how to do this).
> I am trying to use php to validate.  I have been googling and checking
> books and archives for 2 days and all examples use the same file to post
> to.  In other words, form1.php uses form action="form1.php".  But I need
> it to be form(2), but I still need to validate.
> Does anyone have any ideas, or does everyone just use javascript with
> say...alert boxes.  This will be my last resort.

> Here's the code for form1.php


> <form action="form2.php" method="post">

OK when some submits the form the contents are sent to form2.php ...

> <?
> function check_form($comp_name, $city, $state, $contact) {
>         if (!$comp_name || !$city || !$state || !$contact):
>         print ("Please fill in all Fields");
>         if (!$comp_name) {
>         print ("Please fill in your company name");
>         }
>         if (!$city) {
>         print ("Please fill in your city");
>         }
>         if (!$contact) {
>         print ("Please fill in your contact name");
>         }
>         endif;
>         }
> ?>

..., which means this validation doesn't run (it's run when form1.php is first 
displayed, but that's not what you want).

IOW your validation code must be at wherever you set the form action as.

There are at least a couple of ways you can do this:

1) If your forms are related, have a single page which deals your two (or more 
forms). You have to keep track of which stage the user is at (ie if they've 
filled in form1 then you should display form2).

2) Or have it as two pages (like you have now) but in form1.php have the 
action="form1.php" (so it processes its form). After you've processed it, 
stick the values into some session variables then use header() to redirect to 

Or you can have a look at www.phpclasses.org for some classes which can build 
and validate forms for you.

Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

Qvid me anxivs svm?

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to