CrazyEngineers
  • PHP: How to call a function on button click?

    Updated: Oct 25, 2024
    Views: 782
    Hi,
    i am learning php these days.I want to know how to call a php function on button click.
    Button is created in HTML and function is a php function.Give sample code if possible.
    Please help me.
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • itchap

    MemberAug 9, 2009

    Re: help in PHP

    <script language="javascript">
    function check()
    {
    str=document.f.t1.value;
    if(str=="")
    {
    alert("This field can not be empty");
    return false ;
    }

    }

    </script>


    <form action="a.php" method="post" name="f">
    Name <input type="text" name="t1">
    <br>
    <input type="submit" value="submit" onClick="return check();">
    </form>

    I think this will solve your problem. But if you still need further assistance than let me know please.........
    Are you sure? This action cannot be undone.
    Cancel
  • komputergeek

    MemberAug 9, 2009

    Re: help in PHP

    itchap
    I think this will solve your problem. But if you still need further assistance than let me know please.........

    But in this case we will have to create seperate php file for each function.
    Is there any way to write few php functions in one file and call one of them as required?
    Are you sure? This action cannot be undone.
    Cancel
  • itchap

    MemberAug 9, 2009

    Re: help in PHP

    komputergeek
    But in this case we will have to create seperate php file for each function.
    Is there any way to write few php functions in one file and call one of them as required?
    Yeah for this purpose you have to use the isset function i am giving you the syntax for that........
    <?php

    if(isset($_POST["submit']))
    {

    #Put Your code Here

    }

    ?>
    Put this at the top of the page. And all the code written in the if block will be work when the submit button is clicked.
    Are you sure? This action cannot be undone.
    Cancel
  • komputergeek

    MemberAug 11, 2009

    Re: help in PHP

    Thanks.i will try tihs.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register