duanqian8867 2015-03-29 05:57
浏览 35
已采纳

PHP如何通过$ _POST获取输入值类型

Hi I am sending a form through post to a php file that I have made. I have been able to use $_POST["name"] to get the vales of input fields of type text/password,/etc but now I would like to also get their 'type'. So in my variable $car = $_POST["car"]; will store the value, I would like $carInputType to store the inputs type. So if in the form the person chose Mazda in a checkbox, I would like the $carInputType to hold 'checkbox' the type.

I hope I explained this well I think this could be useful for many people to learn. I have been looking around but I have not found ANYTHING to answer this. I have tried:

$radio = $_POST["fname[type]"];
$radio = $_POST["fname[type=]"];

A bit of my form is as follows:

<form id="ajax-form" onsubmit="return false;">
<div><label for="uname">Username <em>*</em></label> <input id="uname"     type="text" name="uname" value=""  /><p class='note' id = "userNameID"></p>        </div>
</form>

Any help would be greatly appreciated. Thank you for reviewing my post.

  • 写回答

1条回答 默认 最新

  • douxin2011 2015-03-29 06:17
    关注

    You can't do this with only PHP. You would use JavaScript or jquery to build the post data as you need it.

    var data =    $('#myForm').serializeArray();    
    data.push({
        name: 'elementName', 
        value: 'elementValue',
        Type: 'element type'
    }); 
    $.post("page.php", data);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计