Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access html 5 data attribute in php

I have a form which includes

<input id="user-id" type="text" data-user-id="" name="message" placeholder="type and send..." class="form-control">

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?

like image 533
Chaudhry Waqas Avatar asked Feb 20 '26 07:02

Chaudhry Waqas


1 Answers

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">

Your message input shouldn't have an id of user-id and shouldn't need data-user-id at all.

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.

like image 150
rybo111 Avatar answered Feb 22 '26 19:02

rybo111