Ph Abd
Ph Abd

Reputation: 87

PHP POST multiple data inside one checkbox

i have following part of code: <input id="add" class="add" data-amount="150" data-monthly="25" type="checkbox" name="accessory[]" value="Accessory Name"/> wondering if there any way to post all data in "value", "data-amount" and "data-monthly" together to another script?

Upvotes: 1

Views: 420

Answers (4)

Scott Saunders
Scott Saunders

Reputation: 30414

To get all those values in the checkbox, you can concatenate them together separated by some delimiter and then split the value when processing the form.

<input type="checkbox" name="accessory[]" value="Accessory Name*150*25"/>

This is not an elegant solution. It does what you ask, but you should strongly consider Sohnee's answer as a better method of doing what you want to do.

Upvotes: 0

Fenton
Fenton

Reputation: 251262

If you are writing the value of those attributes onto the page server side, you are better off working off of a key and retrieving the values again server side based on the key. The HTML could be altered resulting in non-trustworthy data being send back.

For example...

<input id="add" class="add" data-amount="150" data-monthly="25" type="checkbox" name="accessory[]" value="1"/>

Where 1 is the id of the data that contains the amount and monthly data.

Upvotes: 4

Darvex
Darvex

Reputation: 3654

No there is not, however you can put all the attributes you need in hidden fields which are passed with form.

Upvotes: 0

rbaker86
rbaker86

Reputation: 1822

Data attributes are not submitted with form data.

Upvotes: 0

Related Questions