-1

I pass values to my input fields as shown. These values are sensitive values and i want to make the field readonly so users cannot edit values for any reason. The readonly field still allows users to make changes to the assigned values as shown below ?

How can i prevent users from changing the assigned value ?

Index.HTML

<input class="info"><span class="data">GHS <?php echo $info ?></span> />

Broswer

  <input class="info"><span class="data">100</span> />
RoboPHP
  • 410
  • 4
  • 12
  • 1
    You can't prevent users from changing anything in their browser. You can only prevent them from performing operations in your server-side code. If your users aren't allowed to update that value, then don't update it in your PHP code. – David May 14 '19 at 15:50
  • that is invalid html, if you are just wanting to show the value (and post it in a form), why not just show the span and then add the value to a hidden input too? Of course, if people wanted to, the could edit the hidden input value with dom editors so the only way to stop people from editing them is to store them in a server side session – Pete May 14 '19 at 15:51
  • 1
    use readonly="readonly" attribute. – Mohit Kumar May 14 '19 at 15:54
  • https://stackoverflow.com/questions/16109358/what-is-the-correct-readonly-attribute-syntax-for-input-text-elements – Evik Ghazarian May 14 '19 at 16:39

1 Answers1

1

this should do the trick:

<input class="info" readonly value = <?php echo $info ?> >
DCR
  • 14,737
  • 12
  • 52
  • 115