Reputation: 726
I have few forms on the same page, just like this:
<form action='' method='POST' id='PERSON'>
<input type='hidden' id='ID' name='ID' value='123'>
<input type='text' id='NAME' name='NAME' value='John Smith'>
<button type='submit'>submit</button>
</form>
<form action='' method='POST' id='PRODUCT'>
<input type='hidden' id='ID' name='ID' value='123'>
<input type='text' id='NAME' name='NAME' value='sample whatever'>
<button type='submit'>submit</button>
</form>
Is there any way to identify the sender form in the $_POST/$_REQUEST array without any modification on the forms? The problem is when I'm processing these requests I have no idea where the ID and the NAME params came from. The only way I can think of is to modify each input's name like this: name='PERSON.ID' and name='PRODUCT.ID', but someone might have a better idea than that.
Upvotes: 0
Views: 98
Reputation: 15550
You can handle that by getting ;
in handle request. Here is example;
<form action='' method='POST' id='PERSON'>
<input type='hidden' id='ID' name='ID' value='123'>
<input type='text' id='NAME' name='NAME' value='John Smith'>
<input type='hidden' name='formType' value='form1'>
<button type='submit'>submit</button>
</form>
<form action='' method='POST' id='PRODUCT'>
<input type='hidden' id='ID' name='ID' value='123'>
<input type='text' id='NAME' name='NAME' value='sample whatever'>
<input type='hidden' name='formType' value='form2'>
<button type='submit'>submit</button>
</form>
Upvotes: 2