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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With