如何使用PHP获取输入字段值 [英] How to get input field value using PHP

查看:94
本文介绍了如何使用PHP获取输入字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入字段,如下所示:

I have a input field as follows:

<input type="text" name="subject" id="subject" value="Car Loan">

我想获取输入字段值Car Loan并将其分配给会话.如何使用PHP或jQuery做到这一点?

I would like to get the input fields value Car Loan and assign it to a session. How do I do this using PHP or jQuery?

推荐答案

使用PHP的$_POST$_GET超全局变量通过HTML标记的名称检索输入标记的值.

Use PHP's $_POST or $_GET superglobals to retrieve the value of the input tag via the name of the HTML tag.

例如,更改表单中的方法,然后通过输入名称回显该值:

For Example, change the method in your form and then echo out the value by the name of the input:

使用$_GET方法:

Using $_GET method:

<form name="form" action="" method="get">
  <input type="text" name="subject" id="subject" value="Car Loan">
</form>

显示值:

<?php echo $_GET['subject']; ?>

使用$_POST方法:

Using $_POST method:

<form name="form" action="" method="post">
  <input type="text" name="subject" id="subject" value="Car Loan">
</form>

显示值:

<?php echo $_POST['subject']; ?>

这篇关于如何使用PHP获取输入字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆