Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Calling PHP Functions from HTML forms

  • 16-01-2003 09:58PM
    #1
    Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭


    Lo, entirely new to PHP etc.


    Rightio I´m trying to call a PHP Function from an HTML Form. It subscibes to a mailing list.

    So heres a rough idea of what I´ve being trying*



    [PHP]
    <?php

    function signup()
    {
    ....
    }

    ?>

    [/PHP]
    <form name=Email method=POST action=(read below)>
    <input type=text name=Email_addr value=\"Your_email_address\">
    <input type=submit name=\"Email_submit\" value=Submit>
    

    So what I really want to know is if I can call the function signup() from the Action value in the form tag**? and if so how is it done***?




    *Typos may be present as this isn`t the actuall code believe it or not.
    **I´ve already googled. A simple Yes or No will be enough.
    ***Flamage to somebody who actually gives a damn****
    ****to be taken lightly and in good humor


Comments

  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    Haven't looked at PHP in a few months......but I think if you call

    action=$PHP_SELF

    Which will reload your page, with the form variables set, then you can call signup().

    And set a value like:

    <input type=hidden name="submitPressed" value="1">

    in the form.

    Then you can call

    if (submitPressed) {
    signup()
    }


    ...................


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Thanks Seamus, I´ll have a look at doing it that way.:)


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Originally posted by seamus
    And set a value like:

    <input type=hidden name="submitPressed" value="1">

    in the form.

    Better to do check if the page/script has been accessed via HTTP POST or GET for this purpose rather than using hidden fields:
    [PHP]
    <?php
    if (count($HTTP_POST_VARS) > 0) {
    // Process the form variables and subscibe user to the mailing list
    signup($Email_addr);
    } else {
    // Show HTML Form
    ?>
    <form name=Email method=POST action=$PHP_SELF>
    <input type=text name=Email_addr value=\"Your_email_address\">
    <input type=submit name=\"Email_submit\" value=Submit>
    </form>
    <?
    }

    function signup($email) {
    ....
    }
    ?>
    [/PHP]


Advertisement