calling php function from submit button

后端 未结 4 1556
孤街浪徒
孤街浪徒 2021-01-15 08:51

I want to pass the value of input field address to php. So that when i click on submit button it will be store in php.



        
相关标签:
4条回答
  • 2021-01-15 09:27

    what you intend to do can be done as below method.

    <form method="post" >
    
    <input type="text" name="address">
    <input type="submit" name="go">
    
    </form>
    
    
    
    <?php
        if($_POST){
        if(isset($_POST['go'])){
        call();
        }else{
        echo "Error";
        }
        }
        function call(){
        echo "hi";
        echo $_POST['address'];
        }
    ?>
    
    0 讨论(0)
  • 2021-01-15 09:28

    You are mixing PHP and JavaScript. If you want a pure PHP solution you could do something like:

    <?php
    if(isset($_POST['go'])){
         $address = $_POST['address'];
         echo $address;
    }
    ?>
    
    <form method="POST">
      <input type="text" name="address">
      <input type="submit" name="go" method="post">
    </form>
    

    With PHP once the form is submitted you can access form values with $_POST so use $_POST['address'] instead of document.address.value

    0 讨论(0)
  • 2021-01-15 09:38

    use this code

    <input type="text" name="address">
    <input type="submit" name="go" method="post">
    <?php
        if($_POST){
        if(isset($_POST['go'])){
        call();
        }else{
        echo "Error";
        }
    
        function call(){
        echo "hi";
        echo $_POST['address'];
        }
    ?>
    
    0 讨论(0)
  • 2021-01-15 09:45

    Try like this,this is working fine as per your requirement:

    <html>
    <body>
    <form action="" method="post">
    Address: <input type="text" name="name"><br>
    <input type="submit" name="go" value="call" />
    </form>
    
    <?php
    if (isset($_REQUEST['name'])) {
        call();
        }
    ?>
    <?php
    function call() {
     $address= $_POST['name'];
    echo "Address:".$address;
    exit;
    }
    

    Output:-

    For output Click here

    0 讨论(0)
提交回复
热议问题