Thread: Form Validation

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    St. Petersburg, FL
    Posts
    21
    Rep Power
    0
    I am having a break down in the "how to turn the page process.
    If a html form has the action attribute set to itself when the form is sumitted it validates (or not) then how does one get to the next page.

    I have a hidden variable - $validated but am a loss where to go with it.

    My code so far is based on a really sorry book "Professional PHP Programming" and it glosses over or simply dismisses big fundamentals. The book is written for someone that already knos and loves the language.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    16
    Rep Power
    0
    Actually that is a good book you have. You might try reading it all the way through. There are plenty of examples to show you how to do what you are referring to.

    example:

    <?php

    switch ($form) :
    case "validate" :
    if ($accept == 1) {
    echo "Thank you, visit <a href="www.someurl.com">Our Sponsor</a>n";
    } else {
    echo "Sorry you don't agee.<br>n";
    }

    default :
    echo "<form action="$PHP_SELF" method=post>n";
    echo "<select name=accept><option value="1">Agree <option value="2">Disagree</select>n";
    echo "</form>n";
    endswitch;
    ?>
  4. #3
  5. No Profile Picture
    a total freak
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    33
    Rep Power
    15
    you may want to put some javascript to it. ok, say this is a part of the script which validates your form and send it's information to another file..

    ...
    //validation goes here
    if(whatever condition) {
    $validated = 1;
    echo '
    <html><title></title><head>
    <script>
    function sendthis(****) {
    ****.submit();
    }
    </script>
    </head><body onLoad="sendthis(document.damnform);">
    <form action="somewhere" name="damnform">
    <input type="hidden" name="something" value="idduno">
    ...
    ';
    }

    note the <body> part and the script. the onLoad will ensure you that this form will automatically submit itself when loaded; of course, you may want to put some validification function before the html, that's why i putted some simple conditional function..
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    St. Petersburg, FL
    Posts
    21
    Rep Power
    0
    The book misses a decent table of contents, lame index pages and no glossary which you will see when you attempt to use it as a text book. however, I digress

    I'm not having a problem embedding an anchor I' having a problem redirecting the form to another url under software control. At first glance the REFERENCE:HEADER would work eg:

    if ($validated) {
    Header("Location: <A HREF="http://www.domain.com/member.html");" TARGET=_blank>http://www.domain.com/member.html");</A>
    }
    else {
    Header("Location: <A HREF="http://www.domain.com/login.html");" TARGET=_blank>http://www.domain.com/login.html");</A>
    }

    but no joy there either.

    Still stuck checking out (horror) the java app below.

    be a good time to have an idea

    Bill


    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by ray_cormier:
    Actually that is a good book you have. You might try reading it all the way through. There are plenty of examples to show you how to do what you are referring to.

    example:

    <?php

    switch ($form) :
    case "validate" :
    if ($accept == 1) {
    echo "Thank you, visit <a href="www.someurl.com">Our Sponsor</a>n";
    } else {
    echo "Sorry you don't agee.<br>n";
    }

    default :
    echo "<form action="$PHP_SELF" method=post>n";
    echo "<select name=accept><option value="1">Agree <option value="2">Disagree</select>n";
    echo "</form>n";
    endswitch;
    ?>
    [/quote]

  8. #5
  9. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Why don't you tell us what happens when your script hits the header("Location ..)??

    Maybe then we can help you.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    St. Petersburg, FL
    Posts
    21
    Rep Power
    0
    I am trying every combination of the following, with out success.

    The manual insists that there be no output prior to the below: Noticee the example dosen't have script tags (eg <?php ?> ) around it but I have tried every posible combination of the line:

    Header ("Location://www.domain.com/member.html");

    and no joy - thought that I had discovered a new route to nirvana when I found the following fragment - but no... Just another whirlpool of false hope in a sea of dispair.

    Bill

    if ($validated) {
    Header("Location: <A HREF="http://www.domain.com/member.html");" TARGET=_blank>http://www.domain.com/member.html");</A>
    }
    else {
    Header("Location: <A HREF="http://www.domain.com/login.html");" TARGET=_blank>http://www.domain.com/login.html");</A>
    }

    This is from
    http://www.php.net/manual/html/function.header.html for more info.

  12. #7
  13. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    I don't know how else to but this: post your entire script thru the header() statements and tell us EXACTLY what happens. All you are telling us is "no joy" that isn't enough information to help you.
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    St. Petersburg, FL
    Posts
    21
    Rep Power
    0
    Good news, joy in mudville
    Got the header to play with the following:

    <?PHP
    $rs = 0;
    if ($rs == 0) {
    header("Location:http://www.mydomain.com/memberservices.php3");
    exit;
    }

    if ($rs == 1) {
    header("Location: <A HREF="http://www.mydomain.com/Quiz/members.htm");" TARGET=_blank>http://www.mydomain.com/Quiz/members.htm");</A>
    }
    else{
    header("Location: <A HREF="http://www.mydomain.com/Quiz/index.htm");" TARGET=_blank>http://www.mydomain.com/Quiz/index.htm");</A>
    }

    ?>

Similar Threads

  1. form validation!!!
    By boskyvora in forum HTML Programming
    Replies: 5
    Last Post: February 6th, 2004, 08:45 AM
  2. HTTP Error 400: Bad Request, with basic form
    By crackwombat in forum PHP Development
    Replies: 1
    Last Post: January 23rd, 2004, 07:40 PM
  3. dynamic JS form validation
    By rgoel in forum HTML Programming
    Replies: 2
    Last Post: January 8th, 2004, 02:44 AM
  4. Replies: 2
    Last Post: December 23rd, 2003, 05:23 AM
  5. Replies: 0
    Last Post: December 22nd, 2003, 09:02 AM

IMN logo majestic logo threadwatch logo seochat tools logo