Submitting Form to several locations with different buttons

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Submitting Form to several locations with different buttons

Postby cvmflinchy » Sat Feb 06, 2010 2:04 pm

I have a form that people can fill out on a webpage. Once they fill it out they have a choice of three buttons to press. The buttons call a javascript to check that all the boxes are filled in. If they arent then the user is sent back to the field to fill it in correctly. This works fine. BUT no matter what i change (button to a submit or vice versa, adding the different 1.php, 2.php 3.php into the javascript or the onsubmit of the form or the button etc) nothing seems to work. I can put the first location (1.php) into the forms action and call the javascript from the onsubmit (of the form) but even when i have these set it the onclick="document.forms.frmForm.action='2.php';" etc it still calls from 1.php

The java script is the same for all the buttons but the buttons SHOULD send the data to 1.php or 2.php or 3.php depending what the user clicks... the best i can get it is to all submit to 1.php or nothing at all.

Any help would be appreciated asap

Thanks
cvmflinchy
Forum Newbie
 
Posts: 13
Joined: Sat Feb 06, 2010 1:58 pm

Re: Submitting Form to several locations with different buttons

Postby limitdesigns » Sat Feb 06, 2010 11:07 pm

Here's what I would do:

Have the form go to one location. From there, you can route it to one of the three places. You could save all the $_POST variables as session variables, and then route it according to the value of your radio buttons.
limitdesigns
Forum Commoner
 
Posts: 25
Joined: Sat Feb 06, 2010 10:05 pm

Re: Submitting Form to several locations with different buttons

Postby JakeJ » Sun Feb 07, 2010 12:03 am

I agree! That does make the most sense. Besides that, you can perform any processing on that single page you need to such as data validation so you're passing clean data on to other places.
JakeJ
Forum Regular
 
Posts: 631
Joined: Thu Dec 10, 2009 7:27 pm

Re: Submitting Form to several locations with different buttons

Postby cvmflinchy » Mon Feb 08, 2010 6:09 pm

thanks guys ive done it now. I used other buttons to change the action of the form and then submit it in two steps.

Now for my next problem.

I have one text input
I want the user to be able to type several email address into it (seperated by "; ") and the code.php will change the $to = to each email address and send it. i understand i need to use a while function. i do NOT want each email to see all the email addresses on it though just the one its being sent to.

any help?
cvmflinchy
Forum Newbie
 
Posts: 13
Joined: Sat Feb 06, 2010 1:58 pm

Re: Submitting Form to several locations with different buttons

Postby JakeJ » Mon Feb 08, 2010 6:43 pm

parse the string and put it in array and then loop through the array to send the email. Don't forget to validate each email address. This should be helpful: http://htmlfixit.com/cgi-tutes/tutorial_PHP_Splitting_a_String.php
JakeJ
Forum Regular
 
Posts: 631
Joined: Thu Dec 10, 2009 7:27 pm

Re: Submitting Form to several locations with different buttons

Postby cvmflinchy » Mon Feb 08, 2010 7:10 pm

i followed your link and im finally getting there. for some reason though i get this error:
error wrote:Warning: mail() expects parameter 1 to be string, array given in /home/sites/leisure-supplies.co.uk/public_html/admin/newsletter.submit.php on line 30

Newsletter delivery failed... Please try again.


even though this is in my code

Syntax: [ Download ] [ Hide ]
$toemail = $_REQUEST['txtTo'];
 
while ( $splitdata = explode('; ', $toemail))
{
    $to1 = $splitdata;
    line 30: if (mail($to1, $subject1, $body1, $headers1)) {


if txtTo only has one email address in and $to1 = $toemail or "my email" then it works but not with this code.

any idea?

ps. i made a new topic so ill post there
cvmflinchy
Forum Newbie
 
Posts: 13
Joined: Sat Feb 06, 2010 1:58 pm


Return to PHP - Code

Who is online

Users browsing this forum: bk6662 and 1 guest