1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Removing Required Fields Question

Discussion in 'PHP' started by jawinn, Sep 25, 2007.

  1. #1
    I have a form that requires all the fields to be filled in before it submits to an email. I want to remove this restriction. I'm hoping some one can tell me what to change. Any help is much appreciated.

    
    
    <?php
      
      $to = "name@email.com"; // 
      
      if($_POST['send'])
      	{
    	$name = $_POST['name'];
    	$email = $_POST['email'];
    	$best = $_POST['best_time'];
    	$number = $_POST['number'];
    	$description = $_POST['description'];
    	$best_number = $_POST['best'];
    	$alt = $_POST['alt'];
    	
    	if(!$name || !$email || !$best || !$alt || !$description || !$best_number)
    		{
    		echo '<script type="text/javascript">alert("Please ensure all fields are complete");</script>';
    		echo "<meta http-equiv='refresh' content='0; url=contact.php'>";
    		}else{
    		$go++;
    		}
    	if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
    	  $go++;
    	}
    	else {
    		echo '<script language="Javascript">alert ("Email is invlalid") </script>';
    		echo "<meta http-equiv='refresh' content='0; url=contact.php'>";
    	}
    		$headers = "From: $name <$email>\n";
    		$headers .= "Reply-To: $name <$email>\n";
    		
    		$date = date("d/m/y H:s");
    		
    		if($go==2)
    			{
    			mail($to, "Submission on Handy Mensch", "New message has been posted from $name at $date \n\n Persons Name: $name \n Email: $email \n Best Time to contact: $best \n Best Phone Number: $best_number \n\n Alternate Number: $alt \n\n Description: \n $description", $headers);
    			echo "<p style='text-align:center;'>Thank you $name your message has been sent</p>";
    			}
    	}
      ?> 
    
    
    Code (markup):

     
    jawinn, Sep 25, 2007 IP
  2. petronel

    petronel Peon

    Messages:
    113
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    just enter:
    <?php
      
      $to = "name@email.com"; // 
      
      if($_POST['send'])
      	{
    	$name = $_POST['name'];
    	$email = $_POST['email'];
    	$best = $_POST['best_time'];
    	$number = $_POST['number'];
    	$description = $_POST['description'];
    	$best_number = $_POST['best'];
    	$alt = $_POST['alt'];
    	
    
    		$headers = "From: $name <$email>\n";
    		$headers .= "Reply-To: $name <$email>\n";
    		
    		$date = date("d/m/y H:s");
    
    			mail($to, "Submission on Handy Mensch", "New message has been posted from $name at $date \n\n Persons Name: $name \n Email: $email \n Best Time to contact: $best \n Best Phone Number: $best_number \n\n Alternate Number: $alt \n\n Description: \n $description", $headers);
    			echo "<p style='text-align:center;'>Thank you $name your message has been sent</p>";
    
    	}
      ?>
    PHP:
     
    petronel, Sep 25, 2007 IP
  3. jawinn

    jawinn Active Member

    Messages:
    1,024
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    88
    #3
    Thanks but this code doesn't send out an email. After I hit submit I never receive the form data. Any advice?

    thx,

     
    jawinn, Sep 26, 2007 IP
  4. hemlata

    hemlata Peon

    Messages:
    18
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hello,

    the same script is working on my end. Have you checked whether controller is going within if block or not?

    Regards,
     
    hemlata, Sep 26, 2007 IP
    jawinn likes this.
  5. jawinn

    jawinn Active Member

    Messages:
    1,024
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    88
    #5
    Just noticed a syntax error. It's working now. thanks for your help.
     
    jawinn, Sep 26, 2007 IP