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 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程