PHP Form Multiple submitions

CranialBlaze

Expert Member
Joined
Jan 24, 2008
Messages
4,207
Reaction score
1,101
Working on a php form for a competition via Facebook.

Trying to work out a specific trigger for a checkbox, this checkbox is going to trigger the friend invite api which i have setup already, but at the same time it needs to post the form data 5 times instead of once.

Basically checkbox unticked user gets 1 entry, checkbox ticked user gets 5 entries, google is not helping much with this one.

Thanks
 
You want the POST of the form to happen on the checkbox trigger? What if the person doesn't click the checkbox at all, how will the form then submit?

I believe there might be a logic error in how you're approaching the solution.
 
You want the POST of the form to happen on the checkbox trigger? What if the person doesn't click the checkbox at all, how will the form then submit?

I believe there might be a logic error in how you're approaching the solution.

Basically checkbox unticked user gets 1 entry, checkbox ticked user gets 5 entries, google is not helping much with this one.

Nope think you just missed the last line.
 
I recommend that you rethink the checkbox idea. All you need to do is have the person fill in the form, click on "submit", POST the info the database. Then generate a new page or an ajax request to allow the user a new form to enter additional friends. For each validated friend email address, the user gets another entry.
 
I'm not really sure why you would want to POST data 5 times, it seems a bit stupid to do it like that?...

PHP:
$checkbox = $_POST['checkbox'];

if ($checkbox == "x")
{
// Post your data, more complicated coding
}
if ($checkbox == "y")
{
//Post data 5 times, use a loop...
}

Something like that, obviously the top example is super simplified...
 
I recommend that you rethink the checkbox idea. All you need to do is have the person fill in the form, click on "submit", POST the info the database. Then generate a new page or an ajax request to allow the user a new form to enter additional friends. For each validated friend email address, the user gets another entry.

They want facebook integration, the extra entries are directly tied to them inviting friends via facebook, no manual invites at all. If we were not given the job 2 hours before we all went on leave with a deadline 3 days after we all get back to work we would come up with something more elegant but we simply do not have the time.

They will fill in name and email, if they select the invite checkbox it needs to post 5 entries to the database and open up the FB invite window, if they don't tick it it just posts one entry and leave FB invites alone.
Needs to be done tomorrow and we still busy with graphics, everything but the stupid free entries for invites thing is sorted.
 
I'm not really sure why you would want to POST data 5 times, it seems a bit stupid to do it like that?...

PHP:
$checkbox = $_POST['checkbox'];

if ($checkbox == "x")
{
// Post your data, more complicated coding
}
if ($checkbox == "y")
{
//Post data 5 times, use a loop...
}

Something like that, obviously the top example is super simplified...

No argument here, but as explained above don't have the time to be more smart
 
No argument here, but as explained above don't have the time to be more smart

What if you create a 2 Step form? The 1st form determines if they want to only submit one invite or 5... as well as get their email and name. 2nd step will create hidden input types depending on if they want to submit 5 times or once... Then final submit on the 2nd step(form)...?
 
What if you create a 2 Step form? The 1st form determines if they want to only submit one invite or 5... as well as get their email and name. 2nd step will create hidden input types depending on if they want to submit 5 times or once... Then final submit on the 2nd step(form)...?

That was the first idea, set it up that way in the mockup and they did not want it. 1 form, 1 button, simple as possible.

My PHP skills are at best novice, spent all of yesterday just getting to where i am now, took me 2 hours to work out why it was complaining about my checkbox. Eventually figured out i forgot to set the if and isset variables for the database posting.
 
Want to keep it pure php, don't have the time to figure out java as well.

Another suggestion. Create ONE form with all the details, including the 5 friends placed in a DIV, but still part of the FORM. Use a basic Javascript code (using hidden, not hidden) to make the DIV active when the checkbox is selected, hides the list if the checkbox is deselected. Yes, a small bit of javascript, but even I can code that (I am okay with PHP, not good with Javascript). So, if the user selects the checkbox, the five friends list will appear.

Now the trick. The user will post the FORM. If he/she selected and added friends, all you need to do is write your PHP to pick-up that he/she added it (check POST variables is not NULL) and write another entry for the person.

Yes, you still need Javascript, but search for DIV hidden / not hidden Javascript in Google.
 
Nope think you just missed the last line.

Submitting a form based on a checkbox is a stupid ****ing idea because, LIKE I SAID, if they DO NOT click the checkbox the form doesn't submit and they don't get an entry into the competition.

There was no mention of a submit button. So read again, logic error in your brain.

I'd do what creeper said. Remember dude, some of us has been doing this **** for 10+ years now.
 
Submitting a form based on a checkbox is a stupid ****ing idea because, LIKE I SAID, if they DO NOT click the checkbox the form doesn't submit and they don't get an entry into the competition.

There was no mention of a submit button. So read again, logic error in your brain.

I'd do what creeper said. Remember dude, some of us has been doing this **** for 10+ years now.

So i forgot to specifically mention that their is a submit button on the form, pretty much assumed that was logical, how else does one submit a form, you seem to be the only one who never assumed that logic. The check box is a trigger for an additional function on submit, the checkbox itself is not doing the submission, that would be beyond idiotic.

Even with my extremely limited experience i know that. Anyway we solved the problem so thanks.
 
I remember when being a software developer meant, you know, software development. now it means having xammp installed on your pc....

not to be harsh, but how the did you even get this "project" to begin with?????

how to think about and write programs like this is to not confuse presentation with business requirements.

how you see it is:

facebook user -> form -> database

when it is actually
facebook user -> form (all the user needs to do is fill in a form)
form -> controller (POST) (a form just needs to send it's data to an 'action=form.php' (controller)
controller -> (process and save data) (controller uses the data recieved and does what it needs)

^^this is the simple and easy way to do it, but to be fair, you do only realise that with experience :)
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X