Form Submission send other element attributes?
-
12-11-2019 - |
문제
On form submission does anything else get submitted but the value? Can I submit the value and the data-group attribute?
<input type="text" id="theInput" data-group="5" value="the value" />
I'm just talking about a PHP form submission
해결책
Only the value gets submitted, but you can add a hidden element for the data-group value. Also note that you should use a name
attribute to identify the parameter key:
<input type="text" id="theInput" name="theInput" data-group="5" value="the value" />
<input type="hidden" name="theInputGroup" value="5" />
This will come back to the server with the request parameters of:
theInput
⇒the value
theInputGroup
⇒5
Sidenote: If you are submitting the form via ajax, you can just add the group directly into the parameter list instead of adding a hidden input.
제휴하지 않습니다 StackOverflow