I need to pass an id along with a form field e.g
<input name="__field_name" value="1234" />
this only passes the name and value as a key => value pair. i need to keep the name (dynamically entered by the user) and value intact for later use, but i also need to pass an ID along with this var.
how can i do this cleanly? i was thinking putting it in the name and doing a regex to seperate it e.g.
__field_name__ID
although this seems messy…
points to consider:
- there are allot of post variables that are generated by the CMS (wordpress) that i wont use
- name must be retained in original format along with value
Why not submit the data as an array?
Instead of calling your field
__field_name__idor some mess, use the facilities PHP provides: Call your input fieldfield_name[id]and when the form is posted back to the server, PHP’s$_POSTarray will have a sub-array calledfield_namewhich contains the key=>value mappings you’d mentioned.If you have two such fields you want to tie together, use the following:
And on postback, PHP will provide you with a
$_POST['myFields']['id']and$_POST['myFields']['name'].