简体   繁体   中英

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.

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)

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

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.

Once the system works you can hijack it with Javascript and make it more dynamic, if you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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