Wednesday 7 July 2010

PHP and buttons

PHP correctly reports the value of a "type=submit" button in the $_POST array. But if you use a type=button button (eg because you want to validate data before deciding whether to submit) then the value of the button pressed is NOT present in the $_POST array - the button name isn't in the array at all.

Not a big deal (easy enough to set a hidden value, assuming that you use Javascript) but that didn't stop me wasting a lot of time trying to work out what I was doing wrong.