Search code examples
phpjqueryformsattributessubmission

Form Submission send other element attributes?


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


Solution

  • 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:

    • theInputthe value
    • theInputGroup5

    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.