简体   繁体   English

1表格2用验证码提交按钮

[英]1 form 2 submit buttons with captcha

I am working on a booking page form. 我正在使用预订页面表格。 I want a single form where clients fill out their info, and two submit buttons at the bottom: one that holds their reservation for 72 hours, and another that allows them to book now and continue on to a checkout page. 我需要一个表单来填写客户的信息,并在底部有两个提交按钮:一个可以保留其预定时间72小时,另一个可以让他们现在预订并继续进入结帐页面。 The first button should send the data to me via email, then redirect the user to a static html page. 第一个按钮应该通过电子邮件将数据发送给我,然后将用户重定向到静态html页面。 The second button should also send the data to me via email, then redirect the user to a checkout page. 第二个按钮还应该通过电子邮件将数据发送给我,然后将用户重定向到结帐页面。

First, is having two submit buttons in this manner even possible? 首先,是否有可能以这种方式使用两个提交按钮? I've seen posts about having Agree/Disagree buttons, where the disagree button more or less cancels out the form, and the agree button passes on the data. 我看过有关具有“同意/不同意”按钮的帖子,其中“不同意”按钮或多或少取消了表单,“同意”按钮传递了数据。 I need both buttons to pass on data, but with different post actions. 我需要两个按钮来传递数据,但具有不同的后期操作。

Second, I have a free captcha inserted into my form; 其次,我在表格中插入了一个免费的验证码; I'm sick of getting bot form returns in my email inbox. 我讨厌在电子邮件收件箱中获取漫游器表单退回。 I have the captcha working lovely with 1 submit button. 我有1个提交按钮,验证码很可爱。 But I'm at a complete loss for how to impliment the captcha with two submit buttons. 但是我完全不知道如何使用两个提交按钮来暗示验证码。

Here's my code, with the captcha and one working submit button (the other button is not yet "hooked up" and working): 这是我的代码,带有验证码和一个工作的提交按钮(另一个按钮尚未“钩住”并工作):

<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 -->

The captcha can be used multiple times on the same page, according to their website. 根据其网站,验证码可以在同一页面上多次使用。 I really like the images used on SnapHost.com, many of my clients will be older, and these are the easiest images to read that I've come across, so I'm hoping I can keep using SnapHost and still accomplish my double submit button needs. 我真的很喜欢SnapHost.com上使用的图像,我的许多客户端都会比较老,这些是我遇到的最容易阅读的图像,所以我希望我可以继续使用SnapHost并仍然完成我的两次提交按钮的需求。

If anyone has any ideas on (A) if this is do-able and (B) where to begin to code the double submit button/captcha that will work together, I'd really appreciate the help!! 如果有人对(A)是否可行以及(B)在哪里开始编写可一起使用的double Submit button / captcha编码有任何想法,我将非常感谢您的帮助! I'm not sure if I need php (which I know nothing of) or javascript or jQuery (of which I know a little) or something else completely. 我不确定我是否需要php(我一无所知)或javascript或jQuery(我了解一点)或完全需要其他东西。 Thank you!! 谢谢!!


UPDATE 更新


I tried this code, and while it redirects to the correct page, the captcha doesn't validate, AND my form results don't get sent back to me. 我尝试了这段代码,虽然它重定向到正确的页面,但验证码无法验证,并且我的表单结果也不会发送回给我。 Got my hopes up for a moment, only to come crashing back down to earth! 我的希望上升了片刻,然后又坠落了!

<input type="submit" onclick="var e = document.getElementById('mpNOV'); e.action='mp-NOVconfirm.shtml'; e.submit();" 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" onclick="var e = document.getElementById('mpNOV'); e.action='../../index.shtml'; e.submit();" value="Book Now!" class="submit">

I also deleted this 我也删除了这个

input type="hidden" id="skip_WhereToReturn" name="skip_WhereToReturn" value="http://www.happywivestravel.com/tours/machupicchu/mp-NOVconfirm.shtml"

code from the top of the form, thinking it'd be replaced with the onClick function in the input tag, but clearly that's not the answer here. 表单顶部的代码,以为它会被input标签中的onClick函数取代,但是显然这不是答案。

I was hoping for a nice simple fix, but this wasn't it. 我希望有一个简单的好方法,但是不是。 Anyone with any other ideas? 还有其他想法吗?

Update: Checking your code, question and answer again I came up with this: 更新:再次检查您的代码,问题和答案,我想到了这一点:

Javascript : 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>

This part of the code goes on the page where your form lies, I'm not used to working with captcha's so I hope you can figure out the validation yourself. 这部分代码在表单所在的页面上,我不习惯使用验证码,因此希望您自己弄清楚验证。

Original code : 原始代码:

<form action="http://www.SnapHost.com/captcha/send.aspx" method="post" id="mpNOV">

Changed : 已更改:

<form action="http://www.SnapHost.com/captcha/send.aspx" method="post" name="mpNOV" id="mpNOV">

I've added a name to your <form> element in order to interact with it using document.forms . 我已经为您的<form>元素添加了一个名称,以便使用document.forms与之交互。 Further I've noticed that your action in your <form> goes to SnapHost.com. 此外,我注意到您在<form>转到SnapHost.com。 Which means your site will get redirected to SnapHost.com and that you should get the information using $_POST there. 这意味着您的站点将被重定向到SnapHost.com,并且您应该在此处使用$_POST获取信息。 Since this is probably not your website, you should figure out another way to use the SnapHost images on your site without redirecting to SnapHost.com 由于这可能不是您的网站,因此您应该找出另一种使用网站上的SnapHost映像的方法,而无需重定向到SnapHost.com

If this IS your website, then you could use this PHP code to get the Data filled in the form : 如果这是您的网站,则可以使用以下PHP代码以以下形式填写数据:

 <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>

The isset statement checks wether a variable, or in this case a button has been "set". isset语句是否检查变量,或者在这种情况下,已“设置”按钮。 So if you would click your "Reservation" button the if statement sees that the "Reservation" button has been set. 因此,如果您单击“预定”按钮, if语句将显示已设置“预定”按钮。

The PHP part of the code goes into the <head> of the page where your <form action> redirects to. 代码的PHP部分进入<form action>重定向到的页面的<head>

HTML : 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>

Note that I've added a name to the above submit buttons, also note that you should always close <input> elements with the /> tag. 请注意,我已经为上述提交按钮添加了名称,还请注意,您应始终使用/>标记关闭<input>元素。 This is W3C Standard I believe. 我相信这是W3C标准。 Also, so far I've read a submit button can't have a Click function, but I'm not quite sure about this. 另外,到目前为止,我已经阅读了一个提交按钮,但是没有单击功能,但是对此我不太确定。

If you need any help on getting data using PHP & the $_POST method look here : Here . 如果您需要使用PHP和$ _POST方法获取数据的任何帮助,请参见此处: 此处

Note that stackoverflow.com is not for writing you complete code's, searching the web and using google goes first, if you can't figure it out after that, ask here. 请注意,stackoverflow.com并非用于为您编写完整的代码,而是首先搜索网络并使用google,如果之后仍无法解决,请在此处询问。

I hope this helps you. 我希望这可以帮助你。

If you have any questions, feel free to ask! 如果你有任何问题随时问!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM