简体   繁体   English

控制是否已单击提交按钮一次或多次

[英]Controlling if a Submit button has been clicked once or more times

I have a registration form for groups of people, with 2 Submit buttons: (1) Add a participant, (2) Submit group registration. 我有一组人的注册表,带有2个“提交”按钮:(1)添加参与者,(2)提交组注册。

When 'Add a participant' is clicked the first time, I want to create a database entry in some 'group' table (that will group together any participant added in that group). 第一次单击“添加参与者”时,我想在某个“组”表中创建一个数据库条目(它将把在该组中添加的任何参与者分组在一起)。 But then, when more participants are added as the group registration process continues, of course I do NOT want any more entry in this table. 但是,当组注册过程继续进行时,当添加更多参与者时,我当然不希望该表中有更多条目。 Just once. 就一次。

It may sound silly but I can't seem to find a way to do that easily. 听起来可能很愚蠢,但我似乎找不到一种轻松做到这一点的方法。 Any idea? 任何想法? (I work in PHP with WordPress) (我在PHP中使用WordPress)

Have a list of groups available for the 'create participant'. 提供“创建参与者”可用的组列表。 If a radio button (or similar) is selected for 'new group' (with appropriate info filled in) then create it when the participant data is submitted. 如果为“新组”选择了一个单选按钮(或类似按钮)(并填充了适当的信息),则在提交参与者数据时创建它。 Check for duplicates first, though. 不过,请先检查重复项。

As @ayman said - having two submit buttons is not a great approach. 正如@ayman所说-具有两个提交按钮不是一个好方法。 You will confuse your users. 您会混淆您的用户。

This is not a silly question and I don't see a way to do it without at least two buttons, or button-like elements, on a form. 这不是一个愚蠢的问题,在表单上至少要有两个按钮或类似按钮的元素,我看不出有办法做到。 It is common to see this. 这是很常见的。 For example, "Continue Shopping" and "Go to Checkout", not to mention the "Cancel" button. 例如,“继续购物”和“转到结帐”,更不用说“取消”按钮了。 That shouldn't be confusing but don't get carried away with it. 这不应该引起混淆,但是不要被它迷住。

This comment seems to be the key reason for your question: 此评论似乎是您提出问题的主要原因:

someone decides to register several people at once to get a group discount 有人决定一次注册几个人以获得团体折扣

Based on this statement, I am working from the assumption that everyone has to register at the same time for this discount to take effect. 基于此声明,我假设每个人都必须同时注册才能使此折扣生效。 That is, you can't register three people then come back later and register three more. 也就是说,您不能注册三个人,然后稍后再回来注册三个。

And the basic problem seems to be that you want to track how many times the form is submitted. 基本问题似乎是您想跟踪提交表单的次数。 Don't do that. 不要那样做 Tracking how many times the form has been submitted is going to be a real headache. 跟踪提交表单的次数将是一个真正的难题。 Rather than auto-generate a group the first time somebody registers, have an intermediary form for group registration. 拥有一个中间形式的组注册,而不是有人第一次注册时自动生成组。 You'd have: 您将拥有:

  1. Register (Optional: Explanatory page with link(s) to the actual registration form) 注册(可选:解释性页面,带有指向实际注册表格的链接)
  2. Register Group (You can just generate an ID or have people name the group. This ID gets passed to the "add member" form) 注册组(您可以只生成一个ID或让人们为该组命名。此ID将传递到“添加成员”表单中)
  3. Add Member (You can submit a member and redirect back to this form for another member, or hit "done" and go to a "Group" checkout form) 添加成员(您可以提交成员,然后重定向回该表单以获取其他成员,或者点击“完成”并转到“组”结帐表单)
  4. At the "Checkout" form you list group members and provide payment options. 在“结帐”表单中,您可以列出组成员并提供付款方式。 No idea how you plan to accept payment but it doesn't matter. 不知道您打算如何接受付款,但这并不重要。 Presumably you have some third party (Paypal, etc) to handle that. 大概您有一些第三方(Paypal等)来处理。

Basically, you are tracking as much as closely as you can how the big shopping sites handle purchases so the whole thing stays as familiar as possible. 基本上,您会尽可能地密切跟踪大型购物网站处理购买商品的方式,以使整个过程尽可能地熟悉。

You can also have a "Single" registration form if you need one. 如果需要,您也可以有一个“单一”注册表格。

I don't know how you plan to prevent the spamming of this form. 我不知道您打算如何防止这种形式的垃圾邮件。 I'd suggest email verification at the group registration stage. 我建议在小组注册阶段进行电子邮件验证。 That is, require some contact information from whomever is registering the group, send an email, and lock that group's registration until an email is returned. 也就是说,要求正在注册该组的任何人的一些联系信息,发送电子邮件并锁定该组的注册,直到返回电子邮件。 Spammers are unlikely to jump through that hoop. 垃圾邮件发送者不太可能越过这一障碍。

You mentioned that you are using WordPress, so use wp_cron to clean up failed or abandoned registrations after some time limit-- 24 hours, three days, whatever. 您提到您正在使用WordPress,因此请使用wp_cron在一段时间(24小时三天)之后清除失败或被放弃的注册。

Once the system works you can hijack it with Javascript and make it more dynamic, if you want. 系统运行后,您可以使用Java劫持它,并使其更具动态性。

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

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