没有将值输入邮件

时间:2014-12-25 14:41:56

标签: javascript php html email post

我使用java脚本在表单中创建了一个动态下拉列表添加行。在我的形式,我没有得到这个的价值。如果我们填充3行只获得一行值。

我现在更改了代码但却无法提交给电子邮件的代码 给我解决方案我该怎么办呢 enter image description here

<?php
	
	
	echo $_POST['optionval'][0];
	echo $_POST['optionoth'][0];			
	echo $_POST['date'][0];
	echo $_POST['Num'][0];
	echo $_POST['num'][0];
	echo $_POST['optionval'][2];
	echo $_POST['optionoth'][3];			
	echo $_POST['date'][4];
	echo $_POST['Num'][5];
	echo $_POST['num'][6];
	echo $_POST['optionval'][2];
	echo $_POST['optionoth'][2];			
	echo $_POST['date'][2];
	echo $_POST['Num'][2];
	echo $_POST['num'][2];
	
	$optionval= $_POST['optionval']; // required 
		$optionoth= $_POST['optionoth']; // required 
			$date= $_POST['date']; // required 
		$Num= $_POST['Num']; // required 
		$num= $_POST['num']; // required 


	 $email_from = '******@gmail.com';//<== update the email address
	$email_subject = "New Order submission";  
	$message = '<html><body>';
				$message .= '<img src="*******" alt="New Appointment" />';
				$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
				
				$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['optionval']) . "</td></tr>";
				$message .= "<tr><td><strong>Phone No:</strong> </td><td>" . strip_tags($_POST['optionoth']) . "</td></tr>";
					$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['date']) . "</td></tr>";
				$message .= "<tr><td><strong>Phone No:</strong> </td><td>" . strip_tags($_POST['Num']) . "</td></tr>";
	$message .= "<tr><td><strong>Phone No:</strong> </td><td>" . strip_tags($_POST['num']) . "</td></tr>";
				
				$message .= "</table>";
				$message .= "</body></html>";
	
	
	
	$to = "******@gmail.com";//<== update the email address
	$headers = "From: $email_from \r\n";
	//$headers .= "Reply-To: $visitor_email \r\n";
	$headers .= "CC: *******@gmail.com \r\n";
	$headers .= "MIME-Version: 1.0\r\n";
	$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
	
	//Send the email!
	mail($to,$email_subject,$message,$headers);
	//done. redirect to thank-you page.
	if(!isset($_POST['submit']))
	{
		//This page should not be accessed directly. Need to submit the form.
		//echo "error; you need to submit the form!";
	}
	header( 'Location:www.google.com' );
	
	// Function to validate against any email injection attempts
	function IsInjected($str)
	{
	  $injections = array('(\n+)',
				  '(\r+)',
				  '(\t+)',
				  '(%0A+)',
				  '(%0D+)',
				  '(%08+)',
				  '(%09+)'
				  );
	  $inject = join('|', $injections);
	  $inject = "/$inject/i";
	  if(preg_match($inject,$str))
		{
		return true;
	  }
	  else
		{
		return false;
	  }
	}
	
	
	?>
<table border="0" cellpadding="0" cellspacing="0">
            <thead>
                  <tr>
                    <td>Option</td>
                    <td>Text</td>
                    <td>Num</td>
                   <td>No</td>
                  </tr>             
        </thead>
           <tbody class="row">
           		<tr class="row-nt">
                	<td>
                    <select name="optionval[]" class="ceventselect" required="">
                          <option value="option-1" selected="selected">option-1</option>
                          <option value="option-2">option-2</option>
                          <option value="option-3">option-3</option>
                          <option value="option-4">option-4</option>
                         
                      </select>                        
                        <input name="optionoth[]" type="text" class="optionother" style="display: none;margin-top:10px;">
                  </td>
                    <td><input name="date[]" type="text" class="date" required=""></td>
                    <td>
                    	<select name="Num[]" class="form_field_box4 valid" required="">
                          <option value="Num-1" selected="selected">Num-1</option>
                          <option value="Num-2">Num-2</option>
                          <option value="Num-3">Num-3</option>
                          <option value="Num-4">Num-4</option>
                          
                      </select>
                    </td>
                  
                    <td>
                    	<input name="num[]" type="number" class="boxnum"  required="">
                    
                       
                  </td>
                </tr>
           </tbody>
      </table>
        <button class="add-new-evt">Add Row</button>
        

         <input type="submit" value="Submit">

    </div>
</form>  

1 个答案:

答案 0 :(得分:3)

如果您将表单元素的名称从xyz更改为xyz[],那么您应该为每个包含您的值的名称获取一个数组。

E.g。

<input name="date[]" type="text" class="date" value="2014-12-25" required="">
<input name="date[]" type="text" class="date" value="2014-12-24" required="">

应该看起来像:

echo $_POST['date'][0]; //2014-12-25 
echo $_POST['date'][1]; //2014-12-24 

如果每一行都有相同的名称而没有[],则只会提交最后一行的值。