Log in

View Full Version : php form submits to different urls depending on what checkbox is selected



Irishcash33
12-03-2010, 06:19 PM
Hi,
I have searched everywhere and tried a few things with no luck.
I have a php form part of wordpress. I have the form submitting to wordpress and another user management system.

I want 3 checkboxes and depending which is checked, on submit the form data will go to a separate url.

I have this so far


<?php if ($_POST["checkbox"] == "Banking")
{
onsubmit="multiSubmit(this, 'url1');"
}
if ($_POST["checkbox"] == "Insurance")
{
onsubmit="multiSubmit(this, 'url2');"
}
if ($_POST["checkbox"] == "Securities")
{
onsubmit="multiSubmit(this, 'url3');"
}
?>
If i didn't do the multiSubmit, the form would only go to wordpress. Right now with that code, I get an error. Any suggestions on why or better solution to how to do this?

Thanks

traq
12-03-2010, 09:33 PM
you're mixing PHP and javascript. They don't work at the same time: PHP won't know which box is checked until after the form is submitted.

I don't know what the function multiSubmit() does, so I can't help you there.

possible solutions:

1) use javascript (jQuery would be easiest).
When the user clicks the [ submit ] button, fire a function that checks which box is selected, and submit the form to the appropriate url.

2) use php.
Make the form submit to a php page that checks which box is selected, and then re-POST the form to the appropriate url.

Irishcash33
12-03-2010, 09:38 PM
Thanks Trag.
The multiSubmit(); submits the form to 2 locations. Right now I have the form going to Wordpress and another user management system. I'll try option 2, thanks

traq
12-04-2010, 01:55 AM
I figured it did something like that, but without seeing the function itself, I couldn't help you.

If you use PHP to redirect, you might have to use socket connections or cURL to resend the POST variables (as POST). It will depend on how your processing scripts are set up, and if you can modify them at all.

If it's a "black box," as it were, javascript would be the easier option.

p.s., it's " traq " ( Q ). good luck!