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__id
or 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$_POST
array will have a sub-array calledfield_name
which 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']
.You could add a hidden field which contains the input field name value.
You need to add a hidden form field which contains the Id of the first field. You can name it as field1_ID or something.
Or if you are familiar with Javascript, You can post it using javascript with single form field putting the id as an attribute.
here form1 is the name of the form containing the input box.