SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Form validation

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form validation

    Here is my problem.. Take a look a this code.. Sorry about the formating.

    PHP Code:
    <?php                        if (!isset($submited)) {
                            
    ?>
                            <p>Welcome to the update center.  Here you can update the theme to the most recent version<p><br><br>
                            Your current version number (version.txt):<br>
                            <form method="post" action="<?=$PHP_SELF?>">
                            <input name="version" type="text" maxlength="100" size="5">
                            <input type="hidden" name="action" value='update'>
                            <input type=submit name="submited" value="Check">
                            </form>
                            <?php
                            
    } else {
                            
    $query "SELECT * FROM admin WHERE name = 'admin'";
                            
    $result mysql_query($query);
                            
    $row mysql_fetch_array($result);
                            if (
    $row['cversion'] != $version) {
                                if (!isset(
    $submitedok)) {
                                
    ?>
                                <form method="post" action="<?=$PHP_SELF?>">
                                FTP Server: <input name="server" type="text" maxlength="100" size="20"><br>
                                FTP User: <input name="ftpusern" type="text" maxlength="100" size="20"><br>
                                FTP Pass: <input name="ftppass" type="password" maxlength="100" size="20"><br>
                                <input type="hidden" name="action" value='update'>
                                <input type=submit name="submitedok" value="Check">
                                </form>
                                <?php
                                
    } else {
                                    print 
    "$server $ftpusern $ftppass";
                                }
                            } else {
                                    print 
    "You are running the most current version";
                            }
                            }
    So the script firsts asks you for the version number. If it doesn't match the one in the database you have to input more ftp information to allow you to get the new version. It displays the ftp info input boxes, but when I press submit it redirects me to the default update page(where you input the version number) instead of printing the vars.

    Any idea how to fix this?

    Thanks in advance,

    Woody

  2. #2
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try..

    elseif($HTTP_POST_VARS["submitedok"]) {
    print "$server $ftpusern $ftppass";
    }
    http://redgoals.com ... my site ... nuff said

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Didn't work...

    Originally posted by redgoals
    try..

    elseif($HTTP_POST_VARS["submitedok"]) {
    print "$server $ftpusern $ftppass";
    }

  4. #4
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try...

    PHP Code:
    <?php
    if($HTTP_POST_VARS["submitedok"]) {
    $server $HTTP_POST_VARS["server"];
    $ftpusern $HTTP_POST_VARS["ftpusern"];
    $ftppass $HTTP_POST_VARS["ftppass"];
    print 
    "$server $ftpusern $ftppass";
    exit;
    }
    if (!isset(
    $submited)) {
    ?>

    <p>Welcome to the update center.  Here you can update the theme to the most recent version<p><br><br>
    Your current version number (version.txt):<br>
    <form method="post" action="<?=$PHP_SELF?>">
    <input name="version" type="text" maxlength="100" size="5">
    <input type="hidden" name="action" value='update'>
    <input type=submit name="submited" value="Check">
    </form>
    <?php
    } else {
    $query "SELECT * FROM admin WHERE name = 'admin'";
    $result mysql_query($query);
    $row mysql_fetch_array($result);
    if (
    $row['cversion'] != $version) {
    if (!isset(
    $submitedok)) {
    ?>
    <form method="post" action="<?=$PHP_SELF?>">
    FTP Server: <input name="server" type="text" maxlength="100" size="20"><br>
    FTP User: <input name="ftpusern" type="text" maxlength="100" size="20"><br>
    FTP Pass: <input name="ftppass" type="password" maxlength="100" size="20"><br>
    <input type="hidden" name="action" value='update'>
    <input type=submit name="submitedok" value="Check">
    </form>
    <?php
    }
    } else {
    print 
    "You are running the most current version";
    }
    }
    http://redgoals.com ... my site ... nuff said

  5. #5
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi!

    PHP Code:
    <?php if (!isset($HTTP_POST_VARS['submited'])) {
    ?>
    <p>Welcome to the update center. Here you can update the theme to the most recent version<p><br><br>
    Your current version number (version.txt):<br>
    <form method="post" action="<?php echo $PHP_SELF?>">
    <input name="version" type="text" maxlength="100" size="5">
    <input type="hidden" name="action" value='update'>
    <input type="submit" name="submited" value="Check">
    </form>
    <?php

    elseif (isset(
    $HTPP_POST_VARS['submited'])) {
    $query "SELECT * FROM admin WHERE name = 'admin'";
    $result mysql_query($query);
    $row mysql_fetch_array($result);
       if (
    $row['cversion'] != $version) {
         if (!isset(
    $HTTP_POST_VARS['submitedok'])) { ?> 
           <form method="post" action="<?php echo $PHP_SELF?>">
           FTP Server: <input name="server" type="text" maxlength="100" size="20"><br>
           FTP User: <input name="ftpusern" type="text" maxlength="100" size="20"><br>
           FTP Pass: <input name="ftppass" type="password" maxlength="100" size="20"><br>
           <input type="hidden" name="action" value='update'>
           <input type="hidden" name="submited" value="set">
           <input type="submit" name="submitedok" value="Check">
           </form>
           <?php 
           else {
              print 
    "$server $ftpusern $ftppass";
           }
        }
        else {
        print 
    "You are running the most current version";
      }
    }
    I hope I haven't messed up your code now.
    But I think it jumps to the default page everytime because after the second form has been submitted the variable submited is not set anymore. I have added a hidden field and then it should hopefully work.

  6. #6
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to the both of you

    Redgoals second method worked great, so Ia m goin with it.

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One more small problem. To submit the form, you ahve to press teh submit button. You can't simply hit the enter key as a shortcut. Anyway to fix this?

  8. #8
    SitePoint Addict rwar's Avatar
    Join Date
    Sep 2001
    Location
    PF / RS / BR
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it depends of the browser you're using. In IE works (>=5) and Netscape (>=6).
    php? mysql? apache? That's it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •