我有一个有下拉选项的联系人表单,现在我需要根据用户从下拉列表中单击的选项、联系人表单上"Action“的名称来更改,这样我就可以根据那里的选项分配一个不同的PHP文件。我知道我想要什么,我只是有一个困难的时间编码,使其发挥作用。我将提供下面的html表单和PHP。
<div id="form123">
<form id="my-form" action="sitephp.php" method="post">
<table width="343" border="0" align="center">
<tbody>
<tr>
<select name="Machine" required id="Machine" onChange="changeSelectValue();">
<option selected="selected"></option>
<option id="machine 1" value="sitephp1.php">machine 1</option>
<option value="sitephp2.php">machine 2</option>
<option id="machine 3" value="sitephp3.php">machine 3 </option>
</select>
<script type="text/javascript" >
function changeSelectValue() {
var myForm = document.querySelector('#my-form');
var selectValue = document.querySelector('#Machine').value;
var actionFile = '';
switch (selectValue) {
case 'machine 1':
actionFile = 'sitephp1.php';
break;
case 'machine 2':
actionFile = 'sitephp2.php';
break;
case 'machine 3':
actionFile = 'sitephp3.php';
break;
default:
break;
}
myForm.setAttribute('action', actionFile);
}
</script>
<?php
$email1=$_POST['Email1'];
$email2=$_POST['Email2'];
$from=$_POST['Email1'];
$email='YOUR EMAIL HERE';
$subject=" Request ";
$message=$_POST['Box'];
$machine=$_POST['Machine'];
$name=$_POST['Name'];
$phone=$_POST['Phone'];
$number=$_POST['Number'];
$message="Name: ".$name."\r\n"."Phone: ".$phone."\r\n"."Email: " .$from ."\r\n"."Machine: ".$machine."\r\n"."Problem: ".$message ;
if ($number !=10) {
die("You are not a human! or your answer was incorrect!, Please go back and try again.");
}
if(!filter_var($email1, FILTER_VALIDATE_EMAIL)) {
die("Invalid email ($email1)");
}
if ($email1 == $email2) {
mail ($email, $subject, $message, "from:".$from);
echo 'Thanks You for the Maintenance Request! We will Contact you shortly. ';
}
else {
echo "This ($email2) email address is different from ($email1).\n";
}
?>
发布于 2017-05-01 17:19:33
最好有一个主*.php脚本,您可以在其中选择一个取决于用户输入的事件的进一步过程,例如:
switch ( $_POST['Machine'] ) {
case 0:
include 'script1.php';
break;
case 1:
include 'script2.php';
break;
case 2:
include 'script3.php';
break;
}https://stackoverflow.com/questions/43722947
复制相似问题