How to pass form input value to php function











up vote
1
down vote

favorite
1












I want to write a php page in which there is a html form. I want to send all input (number for example) of my form to a php function (instead of a javascript function; I make this to hide my javascript function code).



How can I send input value to php function?

Is it possible to call the php function through onclick="function(param1, param2)"?

I know that javascript is a client-side language while php is server-side.



If it is possible, how can I write the return of the function in an input field?

I want to remain in my page.

Is it correct - action="#"?

My code is:



<form action="#" method="get">
Inserisci number1:
<input type="text" name="val1" id="val1"></input>

<?php echo "ciaoooo"; ?>

<br></br>
Inserisci number2:
<input type="text" name="val2" id="val2"></input>

<br></br>

<input type="submit" value="send"></input>
</form>


Help me in the implementation of the simple php function and in the passage of values from input to function!
Thanks!










share|improve this question
























  • googled it? w3schools.com/php/php_forms.asp
    – jimmy
    Feb 24 '13 at 18:39










  • did you search for ajax ?
    – kirugan
    Feb 24 '13 at 18:40










  • To post to the same page, just use empty action i.e. action="".
    – Igor Jerosimić
    Feb 24 '13 at 18:47










  • @jimmy You might want to see this page w3fools.com W3 Schools (unfortunately) is not a reliable source of information
    – tim.baker
    Feb 24 '13 at 19:02















up vote
1
down vote

favorite
1












I want to write a php page in which there is a html form. I want to send all input (number for example) of my form to a php function (instead of a javascript function; I make this to hide my javascript function code).



How can I send input value to php function?

Is it possible to call the php function through onclick="function(param1, param2)"?

I know that javascript is a client-side language while php is server-side.



If it is possible, how can I write the return of the function in an input field?

I want to remain in my page.

Is it correct - action="#"?

My code is:



<form action="#" method="get">
Inserisci number1:
<input type="text" name="val1" id="val1"></input>

<?php echo "ciaoooo"; ?>

<br></br>
Inserisci number2:
<input type="text" name="val2" id="val2"></input>

<br></br>

<input type="submit" value="send"></input>
</form>


Help me in the implementation of the simple php function and in the passage of values from input to function!
Thanks!










share|improve this question
























  • googled it? w3schools.com/php/php_forms.asp
    – jimmy
    Feb 24 '13 at 18:39










  • did you search for ajax ?
    – kirugan
    Feb 24 '13 at 18:40










  • To post to the same page, just use empty action i.e. action="".
    – Igor Jerosimić
    Feb 24 '13 at 18:47










  • @jimmy You might want to see this page w3fools.com W3 Schools (unfortunately) is not a reliable source of information
    – tim.baker
    Feb 24 '13 at 19:02













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I want to write a php page in which there is a html form. I want to send all input (number for example) of my form to a php function (instead of a javascript function; I make this to hide my javascript function code).



How can I send input value to php function?

Is it possible to call the php function through onclick="function(param1, param2)"?

I know that javascript is a client-side language while php is server-side.



If it is possible, how can I write the return of the function in an input field?

I want to remain in my page.

Is it correct - action="#"?

My code is:



<form action="#" method="get">
Inserisci number1:
<input type="text" name="val1" id="val1"></input>

<?php echo "ciaoooo"; ?>

<br></br>
Inserisci number2:
<input type="text" name="val2" id="val2"></input>

<br></br>

<input type="submit" value="send"></input>
</form>


Help me in the implementation of the simple php function and in the passage of values from input to function!
Thanks!










share|improve this question















I want to write a php page in which there is a html form. I want to send all input (number for example) of my form to a php function (instead of a javascript function; I make this to hide my javascript function code).



How can I send input value to php function?

Is it possible to call the php function through onclick="function(param1, param2)"?

I know that javascript is a client-side language while php is server-side.



If it is possible, how can I write the return of the function in an input field?

I want to remain in my page.

Is it correct - action="#"?

My code is:



<form action="#" method="get">
Inserisci number1:
<input type="text" name="val1" id="val1"></input>

<?php echo "ciaoooo"; ?>

<br></br>
Inserisci number2:
<input type="text" name="val2" id="val2"></input>

<br></br>

<input type="submit" value="send"></input>
</form>


Help me in the implementation of the simple php function and in the passage of values from input to function!
Thanks!







php html forms function






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 4 '16 at 22:31









George Kagan

3,32253548




3,32253548










asked Feb 24 '13 at 18:35









Gio

601313




601313












  • googled it? w3schools.com/php/php_forms.asp
    – jimmy
    Feb 24 '13 at 18:39










  • did you search for ajax ?
    – kirugan
    Feb 24 '13 at 18:40










  • To post to the same page, just use empty action i.e. action="".
    – Igor Jerosimić
    Feb 24 '13 at 18:47










  • @jimmy You might want to see this page w3fools.com W3 Schools (unfortunately) is not a reliable source of information
    – tim.baker
    Feb 24 '13 at 19:02


















  • googled it? w3schools.com/php/php_forms.asp
    – jimmy
    Feb 24 '13 at 18:39










  • did you search for ajax ?
    – kirugan
    Feb 24 '13 at 18:40










  • To post to the same page, just use empty action i.e. action="".
    – Igor Jerosimić
    Feb 24 '13 at 18:47










  • @jimmy You might want to see this page w3fools.com W3 Schools (unfortunately) is not a reliable source of information
    – tim.baker
    Feb 24 '13 at 19:02
















googled it? w3schools.com/php/php_forms.asp
– jimmy
Feb 24 '13 at 18:39




googled it? w3schools.com/php/php_forms.asp
– jimmy
Feb 24 '13 at 18:39












did you search for ajax ?
– kirugan
Feb 24 '13 at 18:40




did you search for ajax ?
– kirugan
Feb 24 '13 at 18:40












To post to the same page, just use empty action i.e. action="".
– Igor Jerosimić
Feb 24 '13 at 18:47




To post to the same page, just use empty action i.e. action="".
– Igor Jerosimić
Feb 24 '13 at 18:47












@jimmy You might want to see this page w3fools.com W3 Schools (unfortunately) is not a reliable source of information
– tim.baker
Feb 24 '13 at 19:02




@jimmy You might want to see this page w3fools.com W3 Schools (unfortunately) is not a reliable source of information
– tim.baker
Feb 24 '13 at 19:02












6 Answers
6






active

oldest

votes

















up vote
5
down vote



accepted










Make your action empty. You don't need to set the onclick attribute, that's only javascript. When you click your submit button, it will reload your page with input from the form. So write your PHP code at the top of the form.



<?php
if( isset($_GET['submit']) )
{
//be sure to validate and clean your variables
$val1 = htmlentities($_GET['val1']);
$val2 = htmlentities($_GET['val2']);

//then you can use them in a PHP function.
$result = myFunction($val1, $val2);
}
?>

<?php if( isset($result) ) echo $result; //print the result above the form ?>

<form action="" method="get">
Inserisci number1:
<input type="text" name="val1" id="val1"></input>

<?php echo "ciaoooo"; ?>

<br></br>
Inserisci number2:
<input type="text" name="val2" id="val2"></input>

<br></br>

<input type="submit" name="submit" value="send"></input>
</form>





share|improve this answer



















  • 1




    form use GET not POST.
    – jcubic
    Feb 24 '13 at 18:58










  • @jcubic form's can use either - especially POST if they are handling sensitive info like email addresses, D.O.B etc
    – tim.baker
    Feb 24 '13 at 19:03










  • @jcubic thanks, I missed that one. - I updated it.
    – Nicholas Pickering
    Feb 24 '13 at 19:07








  • 1




    @tim.baker I know but he write method="get"
    – jcubic
    Feb 24 '13 at 19:07






  • 1




    @NicholasPickering I solved! Thanks a lot! I edit your code, the problem was that the input button did not have the tag name="submit"!
    – Gio
    Feb 27 '13 at 16:13


















up vote
2
down vote













You need to look into Ajax; Start here this is the best way to stay on the current page and be able to send inputs to php.



<!DOCTYPE html>
<html>
<head>
<script>
function showHint(str)
{
var xmlhttp;
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","gethint.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<h3>Start typing a name in the input field below:</h3>
<form action="">
First name: <input type="text" id="txt1" onkeyup="showHint(this.value)" />
</form>
<p>Suggestions: <span id="txtHint"></span></p>

</body>
</html>


This gets the users input on the textbox and opens the webpage gethint.php?q=ja from here the php script can do anything with $_GET['q'] and echo back to the page James, Jason....etc






share|improve this answer





















  • Think that is far to complex for his needs.
    – tim.baker
    Feb 24 '13 at 19:02










  • Why does he need AJAX?
    – Nicholas Pickering
    Feb 24 '13 at 19:09










  • In his question he says "I want to remain in my page" this to me says Ajax.
    – supajason
    Feb 24 '13 at 22:15










  • Remain in my page in the sense that after I click on my button the result is visible in an input field in the same php page.
    – Gio
    Feb 24 '13 at 23:51


















up vote
1
down vote













No, the action should be the name of php file. With on click you may only call JavaScript. And please be aware the hiding your code from the user undermines trust. JS runs on the browser so some trust is needed.






share|improve this answer





















  • Ok @Christoph but I want to hide some formulas. If I use javascript formulas are visible through web browser.
    – Gio
    Feb 24 '13 at 23:49


















up vote
1
down vote













This is pretty basic, just put in the php file you want to use for processing in the element.



For example



<form action="process.php" method="post">


Then in process.php you would get the form values using $_POST['name of the variable]






share|improve this answer






























    up vote
    0
    down vote













    You can write your php file to the action attr of form element.

    At the php side you can get the form value by $_POST['element_name'].






    share|improve this answer




























      up vote
      0
      down vote













      you must have read about function call . here i give you example of it.



      <?php
      funtion pr($n)
      {
      echo $n;
      }
      ?>
      <form action="<?php $f=$_POST['input'];pr($f);?>" method="POST">
      <input name=input type=text></input>
      </form>





      share|improve this answer





















        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














         

        draft saved


        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15055115%2fhow-to-pass-form-input-value-to-php-function%23new-answer', 'question_page');
        }
        );

        Post as a guest
































        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        5
        down vote



        accepted










        Make your action empty. You don't need to set the onclick attribute, that's only javascript. When you click your submit button, it will reload your page with input from the form. So write your PHP code at the top of the form.



        <?php
        if( isset($_GET['submit']) )
        {
        //be sure to validate and clean your variables
        $val1 = htmlentities($_GET['val1']);
        $val2 = htmlentities($_GET['val2']);

        //then you can use them in a PHP function.
        $result = myFunction($val1, $val2);
        }
        ?>

        <?php if( isset($result) ) echo $result; //print the result above the form ?>

        <form action="" method="get">
        Inserisci number1:
        <input type="text" name="val1" id="val1"></input>

        <?php echo "ciaoooo"; ?>

        <br></br>
        Inserisci number2:
        <input type="text" name="val2" id="val2"></input>

        <br></br>

        <input type="submit" name="submit" value="send"></input>
        </form>





        share|improve this answer



















        • 1




          form use GET not POST.
          – jcubic
          Feb 24 '13 at 18:58










        • @jcubic form's can use either - especially POST if they are handling sensitive info like email addresses, D.O.B etc
          – tim.baker
          Feb 24 '13 at 19:03










        • @jcubic thanks, I missed that one. - I updated it.
          – Nicholas Pickering
          Feb 24 '13 at 19:07








        • 1




          @tim.baker I know but he write method="get"
          – jcubic
          Feb 24 '13 at 19:07






        • 1




          @NicholasPickering I solved! Thanks a lot! I edit your code, the problem was that the input button did not have the tag name="submit"!
          – Gio
          Feb 27 '13 at 16:13















        up vote
        5
        down vote



        accepted










        Make your action empty. You don't need to set the onclick attribute, that's only javascript. When you click your submit button, it will reload your page with input from the form. So write your PHP code at the top of the form.



        <?php
        if( isset($_GET['submit']) )
        {
        //be sure to validate and clean your variables
        $val1 = htmlentities($_GET['val1']);
        $val2 = htmlentities($_GET['val2']);

        //then you can use them in a PHP function.
        $result = myFunction($val1, $val2);
        }
        ?>

        <?php if( isset($result) ) echo $result; //print the result above the form ?>

        <form action="" method="get">
        Inserisci number1:
        <input type="text" name="val1" id="val1"></input>

        <?php echo "ciaoooo"; ?>

        <br></br>
        Inserisci number2:
        <input type="text" name="val2" id="val2"></input>

        <br></br>

        <input type="submit" name="submit" value="send"></input>
        </form>





        share|improve this answer



















        • 1




          form use GET not POST.
          – jcubic
          Feb 24 '13 at 18:58










        • @jcubic form's can use either - especially POST if they are handling sensitive info like email addresses, D.O.B etc
          – tim.baker
          Feb 24 '13 at 19:03










        • @jcubic thanks, I missed that one. - I updated it.
          – Nicholas Pickering
          Feb 24 '13 at 19:07








        • 1




          @tim.baker I know but he write method="get"
          – jcubic
          Feb 24 '13 at 19:07






        • 1




          @NicholasPickering I solved! Thanks a lot! I edit your code, the problem was that the input button did not have the tag name="submit"!
          – Gio
          Feb 27 '13 at 16:13













        up vote
        5
        down vote



        accepted







        up vote
        5
        down vote



        accepted






        Make your action empty. You don't need to set the onclick attribute, that's only javascript. When you click your submit button, it will reload your page with input from the form. So write your PHP code at the top of the form.



        <?php
        if( isset($_GET['submit']) )
        {
        //be sure to validate and clean your variables
        $val1 = htmlentities($_GET['val1']);
        $val2 = htmlentities($_GET['val2']);

        //then you can use them in a PHP function.
        $result = myFunction($val1, $val2);
        }
        ?>

        <?php if( isset($result) ) echo $result; //print the result above the form ?>

        <form action="" method="get">
        Inserisci number1:
        <input type="text" name="val1" id="val1"></input>

        <?php echo "ciaoooo"; ?>

        <br></br>
        Inserisci number2:
        <input type="text" name="val2" id="val2"></input>

        <br></br>

        <input type="submit" name="submit" value="send"></input>
        </form>





        share|improve this answer














        Make your action empty. You don't need to set the onclick attribute, that's only javascript. When you click your submit button, it will reload your page with input from the form. So write your PHP code at the top of the form.



        <?php
        if( isset($_GET['submit']) )
        {
        //be sure to validate and clean your variables
        $val1 = htmlentities($_GET['val1']);
        $val2 = htmlentities($_GET['val2']);

        //then you can use them in a PHP function.
        $result = myFunction($val1, $val2);
        }
        ?>

        <?php if( isset($result) ) echo $result; //print the result above the form ?>

        <form action="" method="get">
        Inserisci number1:
        <input type="text" name="val1" id="val1"></input>

        <?php echo "ciaoooo"; ?>

        <br></br>
        Inserisci number2:
        <input type="text" name="val2" id="val2"></input>

        <br></br>

        <input type="submit" name="submit" value="send"></input>
        </form>






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Oct 30 '15 at 16:02

























        answered Feb 24 '13 at 18:40









        Nicholas Pickering

        2,2462042




        2,2462042








        • 1




          form use GET not POST.
          – jcubic
          Feb 24 '13 at 18:58










        • @jcubic form's can use either - especially POST if they are handling sensitive info like email addresses, D.O.B etc
          – tim.baker
          Feb 24 '13 at 19:03










        • @jcubic thanks, I missed that one. - I updated it.
          – Nicholas Pickering
          Feb 24 '13 at 19:07








        • 1




          @tim.baker I know but he write method="get"
          – jcubic
          Feb 24 '13 at 19:07






        • 1




          @NicholasPickering I solved! Thanks a lot! I edit your code, the problem was that the input button did not have the tag name="submit"!
          – Gio
          Feb 27 '13 at 16:13














        • 1




          form use GET not POST.
          – jcubic
          Feb 24 '13 at 18:58










        • @jcubic form's can use either - especially POST if they are handling sensitive info like email addresses, D.O.B etc
          – tim.baker
          Feb 24 '13 at 19:03










        • @jcubic thanks, I missed that one. - I updated it.
          – Nicholas Pickering
          Feb 24 '13 at 19:07








        • 1




          @tim.baker I know but he write method="get"
          – jcubic
          Feb 24 '13 at 19:07






        • 1




          @NicholasPickering I solved! Thanks a lot! I edit your code, the problem was that the input button did not have the tag name="submit"!
          – Gio
          Feb 27 '13 at 16:13








        1




        1




        form use GET not POST.
        – jcubic
        Feb 24 '13 at 18:58




        form use GET not POST.
        – jcubic
        Feb 24 '13 at 18:58












        @jcubic form's can use either - especially POST if they are handling sensitive info like email addresses, D.O.B etc
        – tim.baker
        Feb 24 '13 at 19:03




        @jcubic form's can use either - especially POST if they are handling sensitive info like email addresses, D.O.B etc
        – tim.baker
        Feb 24 '13 at 19:03












        @jcubic thanks, I missed that one. - I updated it.
        – Nicholas Pickering
        Feb 24 '13 at 19:07






        @jcubic thanks, I missed that one. - I updated it.
        – Nicholas Pickering
        Feb 24 '13 at 19:07






        1




        1




        @tim.baker I know but he write method="get"
        – jcubic
        Feb 24 '13 at 19:07




        @tim.baker I know but he write method="get"
        – jcubic
        Feb 24 '13 at 19:07




        1




        1




        @NicholasPickering I solved! Thanks a lot! I edit your code, the problem was that the input button did not have the tag name="submit"!
        – Gio
        Feb 27 '13 at 16:13




        @NicholasPickering I solved! Thanks a lot! I edit your code, the problem was that the input button did not have the tag name="submit"!
        – Gio
        Feb 27 '13 at 16:13












        up vote
        2
        down vote













        You need to look into Ajax; Start here this is the best way to stay on the current page and be able to send inputs to php.



        <!DOCTYPE html>
        <html>
        <head>
        <script>
        function showHint(str)
        {
        var xmlhttp;
        if (str.length==0)
        {
        document.getElementById("txtHint").innerHTML="";
        return;
        }
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
        }
        xmlhttp.open("GET","gethint.php?q="+str,true);
        xmlhttp.send();
        }
        </script>
        </head>
        <body>

        <h3>Start typing a name in the input field below:</h3>
        <form action="">
        First name: <input type="text" id="txt1" onkeyup="showHint(this.value)" />
        </form>
        <p>Suggestions: <span id="txtHint"></span></p>

        </body>
        </html>


        This gets the users input on the textbox and opens the webpage gethint.php?q=ja from here the php script can do anything with $_GET['q'] and echo back to the page James, Jason....etc






        share|improve this answer





















        • Think that is far to complex for his needs.
          – tim.baker
          Feb 24 '13 at 19:02










        • Why does he need AJAX?
          – Nicholas Pickering
          Feb 24 '13 at 19:09










        • In his question he says "I want to remain in my page" this to me says Ajax.
          – supajason
          Feb 24 '13 at 22:15










        • Remain in my page in the sense that after I click on my button the result is visible in an input field in the same php page.
          – Gio
          Feb 24 '13 at 23:51















        up vote
        2
        down vote













        You need to look into Ajax; Start here this is the best way to stay on the current page and be able to send inputs to php.



        <!DOCTYPE html>
        <html>
        <head>
        <script>
        function showHint(str)
        {
        var xmlhttp;
        if (str.length==0)
        {
        document.getElementById("txtHint").innerHTML="";
        return;
        }
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
        }
        xmlhttp.open("GET","gethint.php?q="+str,true);
        xmlhttp.send();
        }
        </script>
        </head>
        <body>

        <h3>Start typing a name in the input field below:</h3>
        <form action="">
        First name: <input type="text" id="txt1" onkeyup="showHint(this.value)" />
        </form>
        <p>Suggestions: <span id="txtHint"></span></p>

        </body>
        </html>


        This gets the users input on the textbox and opens the webpage gethint.php?q=ja from here the php script can do anything with $_GET['q'] and echo back to the page James, Jason....etc






        share|improve this answer





















        • Think that is far to complex for his needs.
          – tim.baker
          Feb 24 '13 at 19:02










        • Why does he need AJAX?
          – Nicholas Pickering
          Feb 24 '13 at 19:09










        • In his question he says "I want to remain in my page" this to me says Ajax.
          – supajason
          Feb 24 '13 at 22:15










        • Remain in my page in the sense that after I click on my button the result is visible in an input field in the same php page.
          – Gio
          Feb 24 '13 at 23:51













        up vote
        2
        down vote










        up vote
        2
        down vote









        You need to look into Ajax; Start here this is the best way to stay on the current page and be able to send inputs to php.



        <!DOCTYPE html>
        <html>
        <head>
        <script>
        function showHint(str)
        {
        var xmlhttp;
        if (str.length==0)
        {
        document.getElementById("txtHint").innerHTML="";
        return;
        }
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
        }
        xmlhttp.open("GET","gethint.php?q="+str,true);
        xmlhttp.send();
        }
        </script>
        </head>
        <body>

        <h3>Start typing a name in the input field below:</h3>
        <form action="">
        First name: <input type="text" id="txt1" onkeyup="showHint(this.value)" />
        </form>
        <p>Suggestions: <span id="txtHint"></span></p>

        </body>
        </html>


        This gets the users input on the textbox and opens the webpage gethint.php?q=ja from here the php script can do anything with $_GET['q'] and echo back to the page James, Jason....etc






        share|improve this answer












        You need to look into Ajax; Start here this is the best way to stay on the current page and be able to send inputs to php.



        <!DOCTYPE html>
        <html>
        <head>
        <script>
        function showHint(str)
        {
        var xmlhttp;
        if (str.length==0)
        {
        document.getElementById("txtHint").innerHTML="";
        return;
        }
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
        }
        xmlhttp.open("GET","gethint.php?q="+str,true);
        xmlhttp.send();
        }
        </script>
        </head>
        <body>

        <h3>Start typing a name in the input field below:</h3>
        <form action="">
        First name: <input type="text" id="txt1" onkeyup="showHint(this.value)" />
        </form>
        <p>Suggestions: <span id="txtHint"></span></p>

        </body>
        </html>


        This gets the users input on the textbox and opens the webpage gethint.php?q=ja from here the php script can do anything with $_GET['q'] and echo back to the page James, Jason....etc







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 24 '13 at 18:45









        supajason

        590312




        590312












        • Think that is far to complex for his needs.
          – tim.baker
          Feb 24 '13 at 19:02










        • Why does he need AJAX?
          – Nicholas Pickering
          Feb 24 '13 at 19:09










        • In his question he says "I want to remain in my page" this to me says Ajax.
          – supajason
          Feb 24 '13 at 22:15










        • Remain in my page in the sense that after I click on my button the result is visible in an input field in the same php page.
          – Gio
          Feb 24 '13 at 23:51


















        • Think that is far to complex for his needs.
          – tim.baker
          Feb 24 '13 at 19:02










        • Why does he need AJAX?
          – Nicholas Pickering
          Feb 24 '13 at 19:09










        • In his question he says "I want to remain in my page" this to me says Ajax.
          – supajason
          Feb 24 '13 at 22:15










        • Remain in my page in the sense that after I click on my button the result is visible in an input field in the same php page.
          – Gio
          Feb 24 '13 at 23:51
















        Think that is far to complex for his needs.
        – tim.baker
        Feb 24 '13 at 19:02




        Think that is far to complex for his needs.
        – tim.baker
        Feb 24 '13 at 19:02












        Why does he need AJAX?
        – Nicholas Pickering
        Feb 24 '13 at 19:09




        Why does he need AJAX?
        – Nicholas Pickering
        Feb 24 '13 at 19:09












        In his question he says "I want to remain in my page" this to me says Ajax.
        – supajason
        Feb 24 '13 at 22:15




        In his question he says "I want to remain in my page" this to me says Ajax.
        – supajason
        Feb 24 '13 at 22:15












        Remain in my page in the sense that after I click on my button the result is visible in an input field in the same php page.
        – Gio
        Feb 24 '13 at 23:51




        Remain in my page in the sense that after I click on my button the result is visible in an input field in the same php page.
        – Gio
        Feb 24 '13 at 23:51










        up vote
        1
        down vote













        No, the action should be the name of php file. With on click you may only call JavaScript. And please be aware the hiding your code from the user undermines trust. JS runs on the browser so some trust is needed.






        share|improve this answer





















        • Ok @Christoph but I want to hide some formulas. If I use javascript formulas are visible through web browser.
          – Gio
          Feb 24 '13 at 23:49















        up vote
        1
        down vote













        No, the action should be the name of php file. With on click you may only call JavaScript. And please be aware the hiding your code from the user undermines trust. JS runs on the browser so some trust is needed.






        share|improve this answer





















        • Ok @Christoph but I want to hide some formulas. If I use javascript formulas are visible through web browser.
          – Gio
          Feb 24 '13 at 23:49













        up vote
        1
        down vote










        up vote
        1
        down vote









        No, the action should be the name of php file. With on click you may only call JavaScript. And please be aware the hiding your code from the user undermines trust. JS runs on the browser so some trust is needed.






        share|improve this answer












        No, the action should be the name of php file. With on click you may only call JavaScript. And please be aware the hiding your code from the user undermines trust. JS runs on the browser so some trust is needed.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 24 '13 at 18:37









        Christoph Grimmer-Dietrich

        2,40932850




        2,40932850












        • Ok @Christoph but I want to hide some formulas. If I use javascript formulas are visible through web browser.
          – Gio
          Feb 24 '13 at 23:49


















        • Ok @Christoph but I want to hide some formulas. If I use javascript formulas are visible through web browser.
          – Gio
          Feb 24 '13 at 23:49
















        Ok @Christoph but I want to hide some formulas. If I use javascript formulas are visible through web browser.
        – Gio
        Feb 24 '13 at 23:49




        Ok @Christoph but I want to hide some formulas. If I use javascript formulas are visible through web browser.
        – Gio
        Feb 24 '13 at 23:49










        up vote
        1
        down vote













        This is pretty basic, just put in the php file you want to use for processing in the element.



        For example



        <form action="process.php" method="post">


        Then in process.php you would get the form values using $_POST['name of the variable]






        share|improve this answer



























          up vote
          1
          down vote













          This is pretty basic, just put in the php file you want to use for processing in the element.



          For example



          <form action="process.php" method="post">


          Then in process.php you would get the form values using $_POST['name of the variable]






          share|improve this answer

























            up vote
            1
            down vote










            up vote
            1
            down vote









            This is pretty basic, just put in the php file you want to use for processing in the element.



            For example



            <form action="process.php" method="post">


            Then in process.php you would get the form values using $_POST['name of the variable]






            share|improve this answer














            This is pretty basic, just put in the php file you want to use for processing in the element.



            For example



            <form action="process.php" method="post">


            Then in process.php you would get the form values using $_POST['name of the variable]







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Feb 24 '13 at 18:47









            saidozcan

            74361832




            74361832










            answered Feb 24 '13 at 18:39









            mongy910

            5211




            5211






















                up vote
                0
                down vote













                You can write your php file to the action attr of form element.

                At the php side you can get the form value by $_POST['element_name'].






                share|improve this answer

























                  up vote
                  0
                  down vote













                  You can write your php file to the action attr of form element.

                  At the php side you can get the form value by $_POST['element_name'].






                  share|improve this answer























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    You can write your php file to the action attr of form element.

                    At the php side you can get the form value by $_POST['element_name'].






                    share|improve this answer












                    You can write your php file to the action attr of form element.

                    At the php side you can get the form value by $_POST['element_name'].







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Feb 24 '13 at 18:42









                    saidozcan

                    74361832




                    74361832






















                        up vote
                        0
                        down vote













                        you must have read about function call . here i give you example of it.



                        <?php
                        funtion pr($n)
                        {
                        echo $n;
                        }
                        ?>
                        <form action="<?php $f=$_POST['input'];pr($f);?>" method="POST">
                        <input name=input type=text></input>
                        </form>





                        share|improve this answer

























                          up vote
                          0
                          down vote













                          you must have read about function call . here i give you example of it.



                          <?php
                          funtion pr($n)
                          {
                          echo $n;
                          }
                          ?>
                          <form action="<?php $f=$_POST['input'];pr($f);?>" method="POST">
                          <input name=input type=text></input>
                          </form>





                          share|improve this answer























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            you must have read about function call . here i give you example of it.



                            <?php
                            funtion pr($n)
                            {
                            echo $n;
                            }
                            ?>
                            <form action="<?php $f=$_POST['input'];pr($f);?>" method="POST">
                            <input name=input type=text></input>
                            </form>





                            share|improve this answer












                            you must have read about function call . here i give you example of it.



                            <?php
                            funtion pr($n)
                            {
                            echo $n;
                            }
                            ?>
                            <form action="<?php $f=$_POST['input'];pr($f);?>" method="POST">
                            <input name=input type=text></input>
                            </form>






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jun 8 '17 at 18:21









                            jasinth premkumar

                            1,2461721




                            1,2461721






























                                 

                                draft saved


                                draft discarded



















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15055115%2fhow-to-pass-form-input-value-to-php-function%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest




















































































                                這個網誌中的熱門文章

                                Academy of Television Arts & Sciences

                                L'Équipe

                                1995 France bombings