我正在尝试在函数内部构建一个简单的联系表单,以便稍后将其添加为短代码。我希望根据" select"更改邮件地址。值。
function contact_form_function() {
switch($_POST['selectedValue']){
case 'webmaster':
$mailbox='webmaster@email.com';
break;
case 'careers':
$mailbox='careersk@email.com';
break;
case 'projects':
$mailbox='projects@email.com';
break;
case 'info':
$mailbox='info@hotmail.com';
break;
default:
// Something went wrong or form has been tampered.
}
?>
<form action="MAILTO:<?php echo($mailbox); ?>" method="post" enctype="text/plain">
<input type="text" name="name" required> Name(required)
<input type="text" name="mail" required> Mail(will not be published, required)
<input type="text" name="website"> Website
<select name="selectedValue">
<option value="webmaster">Website Comment</option>
<option value="careers">Careers Information</option>
<option value="projects">Project Opportunity</option>
<option value="info">Other</option>
</select>
<textarea></textarea>
<?php
echo($mailbox);
?>
<input type="submit"></submit>
</form>
<?php
}
?>
它没有回应任何回复,也没有改变电子邮件地址所以我知道我做错了什么。我只是不知道是什么。我是一名新手,因为任何建议都有帮助。
答案 0 :(得分:1)
您需要在尝试使用之前设置$ mailbox值。我建议使用jQuery。
<script src="jquery.js"></script>
<script type="text/javascript">
jQuery.noConflict();
(function ($) {
function readyFn() {
$("#emailSelect").change(function(){
$("#your_form").attr('action', 'MAILTO:' + $("#emailSelect").val() + '@email.com');
});
}
$(document).ready(readyFn);
})(jQuery);
/*$(document).ready(function(){
$("#emailSelect").change(function(){
$("#your_form").attr('action', 'MAILTO:' + $("#emailSelect").val() + '@email.com');
});
});*/
</script>
...
<form action="" id="yoor_form" method="post" enctype="text/plain">
...
<select name="selectedValue" id="emailSelect">
<option value="webmaster">Website Comment</option>
<option value="careersk">Careers Information</option>
<option value="projects">Project Opportunity</option>
<option value="info">Other</option>
</select>
</form>
答案 1 :(得分:0)
您需要在尝试使用之前设置$ mailbox值。
如果您希望在用户选择下拉列表中的某个选项时在浏览器中发生某些事情,则必须使用javascript,而不是PHP。
答案 2 :(得分:0)
尝试使用该值后,您正在定义$mailbox
。
您必须在$mailbox = ...
之前获得<form>
个内容。