在php中访问html 5数据属性 [英] access html 5 data attribute in php
本文介绍了在php中访问html 5数据属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表格包含
<input id="user-id" type="text" data-user-id="" name="message" placeholder="type and send..." class="form-control">
data-user-id
HTML5数据属性。当我提交表单时,我想在php类中使用data属性的值。如何在php中访问此数据属性?
data-user-id
HTML5 data attribute. When I submit the form, I want to use the value of data attribute in a php class. How to access this data attribute in php?
推荐答案
您的用户ID应位于单独的隐藏字段中,例如:
Your user ID should be in a separate hidden field, such as:
<input type="hidden" name="user_id" value="123">
<input type="text" name="message" placeholder="type and send..." class="form-control">
您的消息
输入不应该有 id
user-id
,不需要 data-user-id
。
Your message
input shouldn't have an id
of user-id
and shouldn't need data-user-id
at all.
JavaScript使用数据属性。隐藏的输入将值传递给用户不需要查看的PHP。两者都没有真正隐藏给用户。
Data attributes are used by JavaScript. Hidden inputs pass values to PHP that the user doesn't need to see. Neither are truly hidden to the user.
这篇关于在php中访问html 5数据属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文