dongtai6741 2014-02-09 05:58
浏览 29
已采纳

使用PHP在同一页面上获取输入值?

Well, first i'm new in PHP. Is there a way to get the input value from a existing input on the page on page load with php and pass it to a variable?

For example i have this input: <input type="text" name="g_id_p" id="example1" value"foo">

I want to do something like this: $got_it = $_GET['g_id_p'];

Sorry again if i wrote my code wrong, im noobie on this. Hope to someone help me.

  • 写回答

3条回答 默认 最新

  • douhu2370 2014-02-09 06:10
    关注

    You can't really get an associated value of an input tag within the same PHP page but what you can do is set the value of a variable beforehand.

    What I mean is, create an array that will store all the values of all the input tags.

    $inputValues = array();
    $inputValues['g_id_p'] = 'foo';
    

    Then when you have the tag later on just echo it from the PHP var.

    <input type="text" name="g_id_p" id="example1" value="<?php echo $inputValues['g_id_p']; ?>">
    

    As you can see, we aren't really 'getting' the value that you set but the end result is the same.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?