Advanced Search

Results 1 to 1 of 1

Thread: Oops! Page not found

  1. #1
    Join Date
    Aug 2011
    Location
    Rep Of Ireland
    Posts
    126
    Thanks
    24
    Thanked 3 Times in 1 Post

    Default Oops! Page not found

    There is something in this code causing the form processing on
    click Sent to present an Oops page! Page not found instead of
    the "Your message has been sent".

    Testing in wamp draws attention to line 58 as follows:


    Notice: Undefined index: name in C:\wamp\www\NewForm\validateClass.php on line 58

    Notice: Undefined index: phone in C:\wamp\www\NewForm\validateClass.php on line 58

    Notice: Undefined index: message in C:\wamp\www\NewForm\validateClass.php on line 58

    Notice: Undefined index: code in C:\wamp\www\NewForm\validateClass.php on line 58

    The contact.php is as follows:
    PHP Code:
    <?php
    // we must never forget to start the session
    session_start();
    ?>

    <?php
    define
    ("EMAIL""xxxxxx@gmail.com");

    $messageErr "";
    $message_text "";
    $errors "";

    $nameErr "";
    $emailErr "";
    $phoneErr "";
    $messageErr "";
    $codeErr "";

    $name "";
    $email "";
    $phone "";
    $message "";
    $code "";

    if(isset(
    $_POST['submit'])) {
     
      include(
    'validateClass.php');
     
      
    //assign post data to variables
        
    $name    trim($_POST['name']);
        
    $email   trim($_POST['email']);
        
    $phone   trim($_POST['phone']);
        
    $message trim($_POST['message']);
        
    $code    trim($_POST['code']);
     
      
    //start validating our form
      
    $v = new validate();
      
    $v->validateStr($name"name"375);
      
    $v->validateEmail($email"email");
      
    $v->validatePhone($phone"phone");
      
    $v->validateStr($message"message"10500); 
      
    $v->validateCode($code"code");
     
      if(!
    $v->hasErrors()) {
            
    $header   "From: $email\n" "Reply-To: $email\n";
            
    $subject  "Contact Form Subject";
            
    $email_to EMAIL;
     
            
    $emailMessage  "Name:    " $name  "\n";
            
    $emailMessage .= "Email:   " $email "\n";
            
    $emailMessage .= "Phone:   " $phone "\n\n";
            
    $emailMessage .= "Message: " $message
       
          
    //use php's mail function to send the email
            
    @mail($email_to$subject ,$emailMessage ,$header ); 
                   
          
    //grab the current url, append ?sent=yes to it and then redirect to that url 
           
    $url "http". ((!empty($_SERVER['HTTPS'])) ? "s" "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];       
           
    header('Location: '.$url."?sent=yes");
          
        } else {
        
    //set the number of errors message
        
    $message_text $v->errorNumMessage();      
     
        
    //store the errors list in a variable
        
    $errors $v->displayErrors();
     
        
    //get the individual error messages
        
    $nameErr    $v->getError("name");
        
    $emailErr   $v->getError("email");
        
    $phoneErr   $v->getError("phone");
        
    $messageErr $v->getError("message");
        
    $codeErr    $v->getError("code");
      } 
    //end of the error check
    }
    // end isset
    ?>

    <!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=utf-8" />
    <meta name="robots" content="noindex, nofollow"/>
    <title>| New PHP Form | </title>
    <link rel="stylesheet" href="styleForm.css" type="text/css" media="screen" />
    </head>
    <body>
      <div id="contact_form_wrap">
        <span class="message"><?php echo $message_text?></span>
        <!--<?php echo $errors?>-->
        <?php if(isset($_GET['sent'])): ?><h2>Your message has been sent</h2><?php endif; ?>
        
          <form id="contact_form" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"/>
        
              <p><label>Name:  <span class="errors"><?php echo $nameErr?></span><span class="required">Required</span>
              <input type="text" name="name" class="textfield" value="<?php echo htmlentities($name); ?>" />
              </label></p>
     
              <p><label>Email:  <span class="errors"><?php echo $emailErr ?></span> <span class="required">Required</span>
              <input type="text" name="email" class="textfield" value="<?php echo htmlentities($email); ?>" />
              </label></p> 

              <p><label>Phone:  <span class="errors"><?php echo $phoneErr ?></span> <span class="required">Required</span>
              <input type="text" name="phone" class="textfield" value="<?php echo htmlentities($phone); ?>" />
              </label></p>
     
              <p><label>Message:  <span class="errors"><?php echo $messageErr ?></span> <span class="required">Required</span>
              <textarea name="message" class="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
              </label></p>
              
         <fieldset>
           <legend>Validate Form  <span class="errors"><?php echo $codeErr ?></span></legend>
             <span class="required">Required</span>
                <center>
                    <img src="randomImage.php" alt="Captcha Image"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="text" name="code" class="data"/>
                    <!--Refresh Validate Code Button Facility-->                
                    <div id="flip"><a href onclick="history.go()" class="link" alt="Refresh Code" /></a></div>
                </center>
          </fieldset>
          
              <p><input type="submit" name="submit" class="button" value="Submit Message" /></p>
          </form>
      </div>
    </body>
    </html>
    The validate.php is as follows:
    PHP Code:
    <?php
    ini_set
    ('display_errors'1);
    ini_set('log_errors'1);
    ini_set('error_log'dirname(__FILE__) . '/error_log.txt');
    ERROR_REPORTING(E_ALL);
    ?>

    <?php

    class validate {

        public 
    $errors = array();

        
    /* Validate message string */
        
    public function validateStr($postVal$postName$min 10$max 500) {    
            if (
    strlen($postVal) < intval($min)) {
                
    $this->setError($postNameucfirst($postName) . " at least {$min} characters long.");
            } else if (
    strlen($postVal) > intval($max)) {
                
    $this->setError($postNameucfirst($postName) . " less than {$max} characters long.");
            }
        }
        
    /* Validate email address */
        
    public function validateEmail($emailVal$emailName) {
            if (
    strlen($emailVal) <= 0) {
                
    $this->setError($emailName"Address Required");
            } else if (!
    preg_match('/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/'$emailVal)) {
                
    $this->setError($emailName"Valid Address Required");
            }
        }
        
    /* Validate phone no to allow numbers only */    
        
    public function validatePhone($phoneVal$phoneName) {
            if (
    strlen($phoneVal) <= 0) {
                
    $this->setError($phoneName"Number Required"); 
            } else if (
    preg_match('/[^0-9]/'$phoneVal)) { 
            
    //} else if (is_numeric ($phoneVal)) {
                
    $this->setError($phoneName"Valid Number Required");
            }
        }
        
    /* Validate captcha entry*/    
            
    public function validateCode($codeVal$codeName) {
            if (
    strlen($codeVal) <= 0) {
                
    $this->setError($codeName"Enter Validate Code");            
            } else if(
    md5($codeVal) != $_SESSION['image_random_value']) {    
                
    $this->setError($codeName"Valid Code Required");
            }
        }
        
    /* sets an error message for a form element*/    
        
    private function setError($element$message) {
            
    $this->errors[$element] = $message;
        }
        
    /* returns the error of a single form element*/
        
    public function getError($elementName) {
            if (
    $this->errors[$elementName]) {
                return 
    $this->errors[$elementName];
            } else {
                return 
    false;
            }
        }
        
    /* displays the errors as an html un-ordered list*/
        
    public function displayErrors() {
            
    $errorsList "<ul class=\"errors\">\n";
            foreach (
    $this->errors as $value) {
                
    $errorsList .= "<li>" $value "</li>\n";
            }
            
    $errorsList .= "</ul>\n";
            return 
    $errorsList;
        }
        
    /* returns whether the form has errors*/
        
    public function hasErrors() {
            if (
    count($this->errors) > 0) {
                return 
    true;
            } else {
                return 
    false;
            }
        }
        
    /* returns a string stating how many errors there were*/
        
    public function errorNumMessage() {
            if (
    count($this->errors) > 1) {
                
    $message "There were " count($this->errors) . " errors sending your message!\n";
            } else {
                
    $message "Please correct the error to send your message!\n";
            }
            return 
    $message;
        }
    }
    ?>
    ********************************************************************************************

    I thought earlier that the following line had something to do with it...

    $url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
    header('Location: '.$url."?sent=yes");

    but my hosting provider has advised the following:

    The Engineers have looked in to this and have confirmed that this code
    will work. It looks like you have coding issue elsewhere that you will
    need to look in to on this.
    *********************************************************************************************
    Last edited by Webiter; 06-25-2012 at 10:53 AM. Reason: Reworked query further to receipt of info from hosting company.

Tags for this Thread

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
  •