Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 1表格2带验证码的提交按钮_Php_Javascript_Forms_Submit_Captcha - Fatal编程技术网

Php 1表格2带验证码的提交按钮

Php 1表格2带验证码的提交按钮,php,javascript,forms,submit,captcha,Php,Javascript,Forms,Submit,Captcha,我正在做一个预订页面表单。我想要一个单一的表单,客户填写他们的信息,在底部有两个提交按钮:一个保存他们的预订72小时,另一个允许他们现在预订并继续到结帐页面。第一个按钮应该通过电子邮件将数据发送给我,然后将用户重定向到静态html页面。第二个按钮还应该通过电子邮件将数据发送给我,然后将用户重定向到签出页面 首先,以这种方式拥有两个提交按钮是可能的吗?我看到过关于使用同意/不同意按钮的帖子,其中不同意按钮或多或少地取消了表单,同意按钮传递数据。我需要两个按钮来传递数据,但具有不同的post操作 第

我正在做一个预订页面表单。我想要一个单一的表单,客户填写他们的信息,在底部有两个提交按钮:一个保存他们的预订72小时,另一个允许他们现在预订并继续到结帐页面。第一个按钮应该通过电子邮件将数据发送给我,然后将用户重定向到静态html页面。第二个按钮还应该通过电子邮件将数据发送给我,然后将用户重定向到签出页面

首先,以这种方式拥有两个提交按钮是可能的吗?我看到过关于使用同意/不同意按钮的帖子,其中不同意按钮或多或少地取消了表单,同意按钮传递数据。我需要两个按钮来传递数据,但具有不同的post操作

第二,我有一个免费的验证码插入我的表格;我讨厌在我的电子邮件收件箱中收到机器人形式的回复。我有一个提交按钮,验证码工作可爱。但是我完全不知道如何用两个提交按钮实现验证码

这是我的代码,带有验证码和一个工作提交按钮,另一个按钮尚未连接并工作:

<h2>Traveler Information</h2>
<form action="http://www.SnapHost.com/captcha/send.aspx" method="post" id="mpNOV">
   <input type="hidden" id="skip_WhereToSend" name="skip_WhereToSend" value="my@email.com" />
   <input type="hidden" id="skip_Subject" name="skip_Subject" value="Reservation" />
   <input type="hidden" id="skip_WhereToReturn" name="skip_WhereToReturn" value="confirm.shtml" />
   <input type="hidden" id="skip_SnapHostID" name="skip_SnapHostID" value="xxx" />

<!-- form start -->
   <table width="558" border="0" cellpadding="2" cellspacing="0">
      <tr>
         <td width="214" align="right"># of Travelers</td>
         <td width="344">
            <select name="travelers" id="travelers">
              <option value="1" selected="selected">1</option>
              <option value="2">2</option>
            </select>
         </td>
      </tr>

      <tr>
         <td align="right">Room type</td>
         <td valign="top">
            <select name="room" id="room">
               <option value="" selected="selected">Select...</option>
               <option value="single">Single (1 bed)</option>
               <option value="double">Double (2 beds)</option>
               <option value="doublePlus">Superior Double (2 beds)</option>
            </select>
         </td>
      </tr>
   </table>
<!-- form end -->

<!-- captcha start -->
<table border="0" align="center" cellpadding="2" cellspacing="0" style="background-color:#b9558b;">
   <tr valign="bottom">
      <td style="padding: 0 4px 8px 8px;">
         <a href="#" onclick="return ReloadCaptchaImage('CaptchaImage');" style="font-size:11px;color: #000;">reload image</a><br />
         <a href="http://www.SnapHost.com"><img id="CaptchaImage" alt="Captcha Code" style="border-width:0px;" title="This Captcha image is intended to prevent spam. The Captcha code is generated by an online form processor. To submit this form, enter the code into the text field. For more information click on the Captcha image." src="http://www.SnapHost.com/captcha/CaptchaImage.aspx?id=PR64FH7HK8F7" /></a>
      </td>

      <td style="padding: 0 8px 8px 4px;">
         <span style="color: #fff;"><i>Enter security code:</i></span><br />
         <input id="skip_CaptchaCode" name="skip_CaptchaCode" type="text" style="width:130px; height:64px; font-size:38px;" maxlength="6" />
      </td>
   </tr>

   <tr>
      <td colspan="2" align="center" style="background-color: #fff;">
         <a href="http://www.SnapHost.com" style="text-decoration:none; font-size:11px; font-family:Verdana, Arial, Helvetica; color:#000099;">This web form is protected from SPAM by <span style="text-decoration:underline;">SnapHost.com</span></a></td>
   </tr>
</table>

<script type="text/javascript">
function ReloadCaptchaImage(captchaImageId) 
{
   var obj = document.getElementById(captchaImageId);
   var src = obj.src;
   var date = new Date();
   var pos = src.indexOf('&rad=');

   if (pos >= 0) 
   { 
      src = src.substr(0, pos); 
   }

   obj.src = src + '&rad=' + date.getTime();
   return false; }
</script>

<!-- end captcha -->
<!-- start submit buttons -->
<table width="558" border="0" cellspacing="0" cellpadding="2">
   <tr>
      <td width="55%" align="right" style="padding-top:10px; padding-bottom:10px; border-top: 1px solid #6f3957;">
         <input type="submit" name="bookMP-nov" value="Hold my reservation" class="submit" />
      </td>

      <td width="45%" style="padding-top:10px; padding-bottom:10px; border-top: 1px solid #6f3957;">
         <input type="submit" name="bookMP-nov" value="Book Now!" class="submit" />
      </td>
   </tr>
</table>
<!-- end submit buttons -->
从表单顶部开始编写代码,认为应该用输入标记中的onClick函数替换它,但显然这不是答案

我希望有一个简单的解决办法,但不是这样。有人有其他想法吗

更新: 再次检查您的代码、问题和答案,我得出以下结论:

Javascript:

<head>
<script type='text/javascript' >
   function validateReservation()
   {
     //You can validate your captcha here
     document.forms['mpNOV'].submit(); //this submits the form
   }

   function validateBooking()
   {
     //You can validate your captcha here
     document.forms['mpNOV'].submit(); //this submits the form
   }
</script>
</head>
isset语句检查是否设置了变量,或者在本例中是否设置了按钮。因此,如果您单击您的预订按钮,if语句将看到预订按钮已设置

代码的PHP部分进入重定向到的页面的底部

HTML:

<td>
    <input type="button" onClick="validateReservation();" value="Hold my reservation" class="submit" name="Reservation" />
</td>
<td width="45%" style="padding-top:10px; padding-bottom:10px; border-top: 1px solid #6f3957;">
    <input type="button" onclick="validateBooking();" value="Book Now!" class="submit" name="Book />
</td>
请注意,我已经为上述提交按钮添加了一个名称,还请注意,您应该始终使用/>标记关闭元素。我相信这是W3C标准。 此外,到目前为止,我已经读到一个提交按钮不能有一个点击功能,但我不太确定这一点

如果您需要有关使用PHP和$\u POST方法获取数据的任何帮助,请查看此处:

请注意,stackoverflow.com不适合编写完整的代码、搜索web和使用google goes,如果您在这之后无法理解,请在此处询问

我希望这对你有帮助


如果您有任何问题,请随时提问

非常感谢你的帮助!我有几个关于代码的问题抱歉,我是个新手php代码到哪里去了?标签之间应该用什么包装?或者在单独的php文档中,或者在我的按钮前插入?另外,谢谢你的代码注释,但是你的代码放在这里的时候会是什么代码呢?这是重定向的隐藏输入类型还是其他类型?这对我的验证码有效吗?非常感谢。我已经编辑了我的代码,我可以给你写完整的代码//你的代码在这里,但是就像我在回答中说的,我们不是来写完整的代码的,我们是来帮助你在正确的方向上。太好了,哈门。我可以编写自己的代码,只是需要澄清代码应该放在哪里。我来试试看有什么效果。我已经在搜索谷歌搜索了,但没有找到任何符合我具体需要的东西。谢谢你的帮助!!预订/预订按钮与验证码验证非常配合。我现在遇到的问题是重定向。带有两个值的内联javascript if/then(一个用于预订,另一个用于预订)在输入标记内工作吗?或者我可以在我的服务器上有一个指向外部php的重定向值链接,在数据通过captcha验证后,在我这边用if/then再次路由和解析到两个重定向页面?这有什么意义吗?我试过了,但是我的验证码抱怨id=skip\u WhereToReturn:function formTypename{if name=='reservation'{window.location=http://www.happywivestravel.com/tours/machupicchu/mp-NOVconfirm.shtml;}否则{window.location=http://www.happywivestravel.com; } }
<head>
<script type='text/javascript' >
   function validateReservation()
   {
     //You can validate your captcha here
     document.forms['mpNOV'].submit(); //this submits the form
   }

   function validateBooking()
   {
     //You can validate your captcha here
     document.forms['mpNOV'].submit(); //this submits the form
   }
</script>
</head>
<form action="http://www.SnapHost.com/captcha/send.aspx" method="post" id="mpNOV">
<form action="http://www.SnapHost.com/captcha/send.aspx" method="post" name="mpNOV" id="mpNOV">
 <head>
       <?php
         if($_SERVER['REQUEST_METHOD'] === 'POST') //This if statement checks wether there's been a $_POST request...
         {
            if(isset($_POST['Reservation']) //Is the Reservation button clicked?
            {
               //You can get your data here using $_POST
            }

            if(isset($_POST['Booking']) //Is the Booking button clicked?
            {
               //You can get your data here using $_POST
            }
         }
       ?>
 </head>
<td>
    <input type="button" onClick="validateReservation();" value="Hold my reservation" class="submit" name="Reservation" />
</td>
<td width="45%" style="padding-top:10px; padding-bottom:10px; border-top: 1px solid #6f3957;">
    <input type="button" onclick="validateBooking();" value="Book Now!" class="submit" name="Book />
</td>