Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Calling PHP Functions from HTML forms

  • 16-01-2003 8: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,317 ✭✭✭✭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