Search code examples
javascriptphphtmlclient-side-attacks

Radio buttons and checkboxes. Prevent changing of the value attribute


So you have a checkbox or a radio button with a predifined value to be sent to the database:

<input name="statement" type="radio" value="AWENSOME">

But someone or a script, with bad intention can easily change the value of your checkbox/radio button with for example a basic "browser page inspect" and then send other value to the databse. For example:

<input name="statement" type="radio" value="NOT SO AWENSOME! STUPID">

How can one prevent that guys? Thank you.


Solution

  • Maybe something like this in your model would help if your are using php:

    if ($data['statement'] == 'AWENSOME' || $data['statement'] == 'FOOBAR' )
    {
       $statement = $data['statement'];
    } else
    {
       // abort the app or return an error to the user
    }