Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Form self-validation and submission

Posted on 2000-05-12
8
Medium Priority
?
286 Views
Last Modified: 2007-11-27
This is a fairly common question that I have never been able to find a good answer for.  What I want to create is a series of forms that validate themselves, and if the information contained in them is correct, write to my database and go to the next form in a series.  I can do this if I write the page as one big .php3 file and use $PHP_SELF as the form action, but I want to break it up among several pages. How can I get the form to redisplay if it hits a flag that the page is incorrect, and go to the next page if the info is valid? Thanks guys.
0
Comment
Question by:vianetman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 8

Expert Comment

by:us111
ID: 2806523
I'm sure that it will work perfectely.
One form, check fields, insert into database and then go to next form.
If I understand what you need ....

<?
function TestField($f)
{
if ($f == "")
      print "<font color='#FF0000'>";
}

$field_list = array("Name", "Firstname");

if ($REQUEST_METHOD == "POST")
{ for($i=0; $i<count($field_list);$i++)
  {     if ($$field_list[$i] == "")
          $err=true;
  }
  if ($err<>true)
  {  #now insert into your databse
     # place your code here

     # then redirect to the next form
     header("Location: nextform.php3");
  }
}
?>

<form action="form.php3" method="post">
<?TestField($Name)?>Name</font>
<input type="text" value="<?print $Name?>" name="Name"><br>
<?TestField($Firstname)?>Firstname</font>
<input type="text" value="<?print $Firstname?>" name="Firstname"><br>
<input type="submit" value="submit" name="submit">
</form>
0
 

Author Comment

by:vianetman
ID: 2807514
That is sort of what I was trying to do, but I want to do it without a header() redirect function.  In some circumstances I want to validate the form on the same page, but still submit the data to the next page via the post method.  Any ideas?  Thanks.
0
 
LVL 8

Expert Comment

by:us111
ID: 2808217
I don't really understand why you need to post again the data to the next form after validating the form.
If you insert them in a database, you can easily get them in the next form.

well try
<?
include("nextform.php3")
exit();
?>

instead of header...
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Expert Comment

by:freshmeat
ID: 2809062
why not try javascript on client?
0
 
LVL 8

Expert Comment

by:us111
ID: 2809633
I think it's better to use PHP, you don't depend of the browser.
0
 

Author Comment

by:vianetman
ID: 2811736
I mostly want to pass the data to the next page because I want it to pass some sort of identifying information, such as a user ID, so I will know to whom the data entered on the next page belongs to.  I know, I know, PHP4 has user tracking functions built in, but I cannot install any non-release quality software on the server, so I am stuck with PHP3.  Also, I am not going to spend all day installing the extra librarys needed for PHP3 to do session tracking.  I know the other option is client sided cookies, but I hate dealing with cookies.

Thanks for all the help. I am going to wait another day or two to give up the points in case someone has a miraculous answer that hasen't read this yet.
0
 
LVL 8

Accepted Solution

by:
us111 earned 300 total points
ID: 2813333
with the following solution, for example if you have an ID

<?  ### form.php3
                      function TestField($f)
                      {
                      if ($f == "")
                            print "<font color='#FF0000'>";
                      }

                      $field_list = array("Name", "Firstname");

                      if ($REQUEST_METHOD == "POST")
                      { for($i=0; $i<count($field_list);$i++)
                        {     if ($$field_list[$i] == "")
                                $err=true;
                        }
                        if ($err<>true)
                        {  #now insert into your databse
                           # place your code here

                           # then redirect to the next form
                           include("nextform.php3");
                           exit();
                        }
                      }
                      ?>

<form action="form.php3" method="post">
                      <?TestField($ID)?>ID</font>
                      <input type="hidden" value="<?print $ID?>" name="ID"><br>
                      <?TestField($Name)?>Name</font>
                      <input type="text" value="<?print $Name?>" name="Name"><br>
                      <?TestField($Firstname)?>Firstname</font>
                      <input type="text" value="<?print $Firstname?>" name="Firstname"><br>
                      <input type="submit" value="submit" name="submit">
                      </form>


and
nextform.php3
<?
........

........
?>
<form action="nextform.php3" method="post">
                      <input type="hidden" value="<?print $ID?>" name="ID"><br>
                      <input type="submit" value="submit" name="submit">
                      </form>



your ID will be define in the nextform.php3 page........

I'm lost with your question and your problem.
0
 

Author Comment

by:vianetman
ID: 2814614
I guess that will have to do.  PHP just does not have what I need here.  Sorry to be so picky.  Thanks for all of your help!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question