Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2006
    Posts
    89
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Form processing problem - since using PHP5?

    Hi there,

    I've been using this form for a while now, without problems. However, i'm using it on a new site and its not working. The idea is that the form posts to itself, and then the data is checked. If the form fields are not filled out or the email address is not valid when the form is submitted, then an error message is displayed and the field is highlighted with three red stars ***. The form fields retain their entries if there is an error. The problem is that the even though I don't fill any form fields in, there are no error messages displayed......the page just refreshes over and over.

    I have narrowed down my code just to two form fields, for testing purposes, but still it doesn't work.

    I think it might be the functions that are the problem, as they are quite old. Can someone please advise?

    Here is the included file data_valid.php which checks if the form fields are filled, and if the email address is valid:

    PHP Code:
    <?php
    function filled_out($form_vars)
    {
      
    // test that each variable has a value
      
    foreach ($form_vars as $key => $value)
      {
         if (!isset(
    $key) || ($value == "")) 
            return 
    false;
      } 
      return 
    true;
    }

    function 
    valid_email($address)
    {
      
    // check an email address is possibly valid
      
    if (ereg("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$"$address))
        return 
    true;
      else 
        return 
    false;
    }
    ?>
    And here is the php page:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title></title>
    </head>
    <body>
        <div id="middle">
        <?php
        
    include("inc/data_valid.php")
        
        
    //allows form fields to be remebered when user hits sumbit
                  
    if(isset($_POST['submit'])){ 
                    
    $field1 $_POST['name']; 
                    
    $field2 $_POST['email']; 
                    
    //if form is submitted set fieldHidden variable to the value of the form field submit_check
                    //if form has been submitted then submit_check will have value 'set'
                    
    $fieldHidden $_POST['submit_check']; 

                  } else { 
                       
    $field1 ''
                    
    $fieldHidden '';    
                   } 

                 
    //checks to see if image verification was valid, checks if email was valid and if all form 
                // fields were filled in. If so, form was valid and we enter data to database and send confirmation email.
                 
                
    if (valid_email($email) && filled_out($HTTP_POST_VARS) && isset($_POST["savereview"])){
                 echo 
    "Thank you, your online booking was taken and we will contact you shortly"
                 
                
    //SQL to insert database entries will follow here.............
                
    }
                
                
    //if form has been submitted and there were one or more errors, print message to inform user
                 
    if($fieldHidden == 'set'){
                     if (!
    valid_email($email) || !filled_out($HTTP_POST_VARS)){
                         echo 
    "<font color='red'>There are errors in your form please correct them and submit the form again</font>";
                     }
                 }
          
    ?>
          <form method="post" action="">
            <table class="border" cellpadding="3"  bgcolor="#000000" width="100%"  >
              <tbody>
                <tr>
                  <td valign="top" colspan="3">
                      <!--Set hidden field which allows to check if form has already been submitted-->
                      <input type="hidden" name="submit_check" value="set" />
                      </td>
                </tr>
                <tr>

                  <td width="242" height="25px">Your name:</td>
                  <td width="194"><input name="name" id="name" size="30" value="<? echo $field1?>" type="text" style="width:95%;" /></td>
                  <td width="11%">
                  <?php
                          
    if($fieldHidden == 'set'){
                              if (
    $_POST['name'] == ''){  
                               echo 
    "<font color='red'> *** </font>";
                              }
                          }
                   
    ?>
                  </td>
                </tr>
                <tr>

                  <td width="242" height="25px">Your email:</td>
                  <td width="194"><input name="email" id="email" size="30" value="<? echo $field2?>" type="text" style="width:95%;" /></td>
                  <td width="11%">
                  <?php
                          
    if($fieldHidden == 'set'){
                              if (
    $_POST['email'] == ''){  
                               echo 
    "<font color='red'> *** </font>";
                              }
                          }
                   
    ?>
                  </td>
                </tr>
               
                <tr>
                   <td colspan="3" style="text-align: center;"><input name="savereview" type="submit" class="button" value="Submit" /></td>
               </tr>
              </tbody>
            </table>
          </form>
        </div>
    </body>
    </html>
    Any help would be greatly appreciated.
    Jp

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,038
    Thanks
    2
    Thanked 316 Times in 308 Posts
    $HTTP_POST_VARS were depreciated long ago, turned off by default in php5, and are eliminated in php6.

    Your code is using an inconstant mix of $HTTP_POST_VARS and $_POST. Change all $HTTP_POST_VARS to $_POST

    Also, turning on full php error reporting would alert you to variables that are referenced in the code but don't exist.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New Coder
    Join Date
    Jan 2006
    Posts
    89
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    $HTTP_POST_VARS were depreciated long ago, turned off by default in php5, and are eliminated in php6.

    Your code is using an inconstant mix of $HTTP_POST_VARS and $_POST. Change all $HTTP_POST_VARS to $_POST

    Also, turning on full php error reporting would alert you to variables that are referenced in the code but don't exist.
    ah i see. I quickly changed all $HTTP_POST_VARS to $_POST, but it still fails to work.

    I will turn on full error reporting later tonight as I am going out now.

    If anyone has any other suggestions i'd really appreciate it.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    This function call
    PHP Code:
    valid_email($email
    is calling a non-existent string. That should be $field2 rather than $email. I'm guessing you didn't write the original script.

    Actually it looks like you relied on register_globals being on. This is bad practice as it leaves you open to security risks. Luckily your current host seems to have turned them off.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New Coder
    Join Date
    Jan 2006
    Posts
    89
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    This function call
    PHP Code:
    valid_email($email
    is calling a non-existent string. That should be $field2 rather than $email. I'm guessing you didn't write the original script.

    Actually it looks like you relied on register_globals being on. This is bad practice as it leaves you open to security risks. Luckily your current host seems to have turned them off.
    Hey there

    Yeah I wrote the script, with the help of people on forums.

    I missed out the name="sumbit" on the submit input


  •  

    Posting Permissions

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