Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2004
    Posts
    128
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Form Question - How to use function() in the action=""

    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:

    Code:
    <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:
    PHP Code:
    <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...

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    PHP Code:
    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 ...
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Posts
    128
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by raf
    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
    PHP Code:
    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...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •