Undefined index

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mediator
    New Member
    • Jun 2010
    • 2

    Undefined index

    Hello I have a php contact email form on my a ecommerce shop website !

    I am getting a Undefined index error messages coming from the top of the php code, the email form its self works fine,

    HERE IS THE ERROR MESSAGES


    Notice: Undefined index: Name in E:\domains\t\to ols2diy.co.uk\u ser\htdocs\cont act.php on line 13

    Notice: Undefined index: Tel in E:\domains\t\to ols2diy.co.uk\u ser\htdocs\cont act.php on line 14

    Notice: Undefined index: Email in E:\domains\t\to ols2diy.co.uk\u ser\htdocs\cont act.php on line 15

    Notice: Undefined index: Message in E:\domains\t\to ols2diy.co.uk\u ser\htdocs\cont act.php on line 16



    The code im using is as follows :


    Code:
    <?php
    session_cache_limiter('none');
    session_start();
    ob_start();
    ?>
    
    <?php
    
    $EmailFrom = "info@mediadiverse.org.uk";
    $EmailTo = "info@mediadiverse.org.uk";
    $Subject = "Tools2diy Enquiry";
    $Name = Trim(stripslashes($_POST['Name'])); 
    $Tel = Trim(stripslashes($_POST['Tel'])); 
    $Email = Trim(stripslashes($_POST['Email'])); 
    $Message = Trim(stripslashes($_POST['Message'])); 
    
    // validation
    if (isset($_POST['submit'])) $validate = validateform($Name, $Tel, $Email, $Message);
    
    // prepare email body text
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Tel: ";
    $Body .= $Tel;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";
    
    // send email 
    if (isset($_POST['submit']) && $validate['false'] != true){
     mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
     $emailsent = true;
    }
    
    function validateform($Name, $Tel, $Email, $Message){
      //Check empty fields
      if ($Name == ''){
        $return['false'] = true;
        $return['nameblank'] = true;
      }
      if ($Tel == ''){
        $return['false'] = true;
        $return['telblank'] = true;
      }
      if ($Email == ''){
        $return['false'] = true;
        $return['emailblank'] = true;
      }
    
      if ($Message == ''){
        $return['false'] = true;
        $return['messageblank'] = true;
      }
    
      //Check phone number is digits and spaces only
      if (!is_numeric(str_replace(' ','',$Tel))){
       $return['phone'] = true;
       $return['false'] = true;
      }
    
      //Check email is valid
      if (!preg_match('/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/',$Email)){
       $return['email'] = true;
       $return['false'] = true;
      }
    
      //CAPTCHA
      if($_POST['secure'] != $_SESSION['security_number']){
       $return['captcha'] = true;
       $return['false'] = true;
      }
    
      return $return;
      
    }
    ?>


    The strange thing is that im using the exact same code in another site which is hosted on another server ! but its error free and my current hosting have told me its not the hosting so im stuck !

    Any help would be great
    Last edited by Dormilich; Jun 7 '10, 12:54 PM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    it just means, those indices are not in the $_POST array, either because there are no $_POST data at all (e.g. no form submitted via POST) or the indices are spelled wrong.
    test with var_dump($_POST );

    Comment

    • mediator
      New Member
      • Jun 2010
      • 2

      #3
      Hi the form is below ! the form works just cant get rid of the errors




      PHP ABOVE HEADER

      Code:
      <?php
      session_start();
      $EmailFrom = "info@mediadiverse.org.uk";
      $EmailTo = "info@mediadiverse.org.uk";
      $Subject = "Tools2diy Enquiry";
      $Name = Trim(stripslashes($_POST['Name'])); 
      $Tel = Trim(stripslashes($_POST['Tel'])); 
      $Email = Trim(stripslashes($_POST['Email'])); 
      $Message = Trim(stripslashes($_POST['Message'])); 
      
      // validation
      if (isset($_POST['submit'])) $validate = validateform($Name, $Tel, $Email, $Message);
      
      // prepare email body text
      $Body = "";
      $Body .= "Name: ";
      $Body .= $Name;
      $Body .= "\n";
      $Body .= "Tel: ";
      $Body .= $Tel;
      $Body .= "\n";
      $Body .= "Email: ";
      $Body .= $Email;
      $Body .= "\n";
      $Body .= "Message: ";
      $Body .= $Message;
      $Body .= "\n";
      
      // send email 
      if (isset($_POST['submit']) && $validate['false'] != true){
       mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
       $emailsent = true;
      }
      
      function validateform($Name, $Tel, $Email, $Message){
        //Check empty fields
        if ($Name == ''){
          $return['false'] = true;
          $return['nameblank'] = true;
        }
        if ($Tel == ''){
          $return['false'] = true;
          $return['telblank'] = true;
        }
        if ($Email == ''){
          $return['false'] = true;
          $return['emailblank'] = true;
        }
      
        if ($Message == ''){
          $return['false'] = true;
          $return['messageblank'] = true;
        }
      
        //Check phone number is digits and spaces only
        if (!is_numeric(str_replace(' ','',$Tel))){
         $return['phone'] = true;
         $return['false'] = true;
        }
      
        //Check email is valid
        if (!preg_match('/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/',$Email)){
         $return['email'] = true;
         $return['false'] = true;
        }
      
        //CAPTCHA
        if($_POST['secure'] != $_SESSION['security_number']){
         $return['captcha'] = true;
         $return['false'] = true;
        }
      
        return $return;
        
      }
      ?>



      BODY CONTENT FORM

      Code:
      <?php if (isset($emailsent) && ($emailsent == true))
      	    echo '<p style="text-align: center">Your message has been sent we will be in touch soon!</p>';
      ?>
      				
      <div id="contact-area">
      			
      			    <form method="post" action="contact.php">
      				
      				<div><label for="Name" id="Name">Your name:</label>
      				<input type="text" name="Name" value="<?php if (isset($_POST['Name'])) echo htmlentities($_POST['Name']) ?>"/>
      				<?php if (isset($validate['nameblank'])) echo '<span class="formerror">You need to complete this field</span>'; ?>
      				</div>
      				
      				<div><label for="Tel" id="Tel">Your Tel:</label>
      				<input type="text" name="Tel" value="<?php if (isset($_POST['Tel'])) echo htmlentities($_POST['Tel']) ?>"/>
      				<?php if (isset($validate['telblank'])) echo '<span class="formerror">You need to complete this field</span>'; ?>
      			        <?php if (isset($validate['phone'])) echo '<span class="formerror">Invalid phone number</span>'; ?>
      		          </div>
      	
      			    	<div><label for="Email" id="Email">Your email:</label>
      				<input type="text" name="Email" value="<?php if (isset($_POST['Email'])) echo htmlentities($_POST['Email'])?>"/>
      				<?php if (isset($validate['emailblank'])) echo '<span class="formerror">You need to complete this field</span>'; ?>
      			        <?php if (isset($validate['email'])) echo '<span class="formerror">Invalid email address</span>'; ?>
      				</div>
      				
      				<div><label for="Message" id="Message">Your message :</label>
      				<textarea name="Message" rows="20" cols="20"><?php if (isset($_POST['Message'])) echo htmlentities($_POST['Message']) ?></textarea>
      				<?php if (isset($validate['messageblank'])) echo '<span class="formerror">You need to complete this field</span>'; ?>
      				</div>
      				
      	             <div>
      			   <label for="captcha" id="captcha">Please answer this </label>
      				<img src="includes/image.php" alt="CAPTCHA" name="captcha" id="captcha"  />
      				
      </div>
                     
      				
      				<div><label>Input the answer</label>
      				 <input type="text" rows="20" cols="20" name="secure" />
      				<?php if (isset($validate['captcha'])) echo '<span class="formerror">Invalid response</span>'; ?>
      				</div>
      				
      				
      				
      				<div><label><input type="submit" name="submit" value="Submit" class="submit-button" />
      			    </label>
      				</div>
      			</form>
      Last edited by Dormilich; Jun 7 '10, 03:50 PM. Reason: Please use [code] tags when posting code

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        kill the email script, if you don’t find the $_POST variables.

        Comment

        Working...