...

View Full Version : Form Question - How to use function() in the action=""



XtremeGamer99
09-23-2004, 07:00 AM
Okay, I haven't tried this yet, i wanted to know before I failed at it.

I have this mailing script the emails me the information in a form. I have multiple forms on my site, so I have all the scripts inside one file (mailer.php), and it uses functions to separate the different scripts. Now, I think that you use something like this:


<form method="post" action="FUNCTION_GOES_HERE">

and have the mailer.php file be included at the top of the form page, so it can get that function. ie:


<form method="post" action="<?php submit_code_mailer(); ?>">

But, I'm not sure it would work. If not, how do I et the form action to do a function?

Thanks in advance... ;)

raf
09-23-2004, 08:49 AM
i don't realy understand that explanation, and it seams to me you're confusing a few things.
something like
<form method="post" action="<?php submit_code_mailer(); ?>">
would mean that the code in bold would be executed before the form is sent to the browser, so only the result of the function would be sent to the client.

I assume you wanna know which form the client posted (which forms button he hit or so). Well, you just give each sumitbutton a different name or you give them all a diferent value. And then all you need to do is check which buttons-value is posted. Or you just include e hidden field inside each form, and give it the value for that form. Like inside form 1 you include

<input type="hidden" id="form" name="form" value="1" />

and inside form 2 you include

<input type="hidden" id="form" name="form" value="2" />

etc

In your processing page, you then just put something like


switch($_POST['form']){
case '1':
//your code to proces form 1
break;
case '2':
//your code to proces form 1
break;
default:
die ('Invalid formaction');
}

the processing code can be a redirect or so ...

XtremeGamer99
09-23-2004, 07:14 PM
i don't realy understand that explanation, and it seams to me you're confusing a few things.
something like
<form method="post" action="<?php submit_code_mailer(); ?>">
would mean that the code in bold would be executed before the form is sent to the browser, so only the result of the function would be sent to the client.

I assume you wanna know which form the client posted (which forms button he hit or so). Well, you just give each sumitbutton a different name or you give them all a diferent value. And then all you need to do is check which buttons-value is posted. Or you just include e hidden field inside each form, and give it the value for that form. Like inside form 1 you include

<input type="hidden" id="form" name="form" value="1" />

and inside form 2 you include

<input type="hidden" id="form" name="form" value="2" />

etc

In your processing page, you then just put something like


switch($_POST['form']){
case '1':
//your code to proces form 1
break;
case '2':
//your code to proces form 1
break;
default:
die ('Invalid formaction');
}

the processing code can be a redirect or so ...

Well, I don't know much about switches ore cases, since I've never used them before. I'll look into it, but it seems to me that give each form a unique value, and have the code above execute the script, depending on what the value is? Again, I'll look into it, and try it out...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum