0

As the title suggests, I have a form, which as soon as the user registers he is forced to compile, then the user can return to this form, and obviously the form on the screen will present the choices that the user has previously made, now to make that the checkbox is enabled if the user has previously pressed on the checkbox, I succeed with this code here, and the checkbox, appears to me on the selected screen:

<input <?php if (!(strcmp($row_mostra_tabella_email['aut_privacy'],"S"))) {echo "checked=\"checked\"";} ?> type="checkbox" id="aut_privacy" type="checkbox" value="S"  name="aut_privacy" >

the problem is that if I do the same thing with the disabled command, when the user presses enter, I don't pass the command value = "s".

I would just like the checkbox to be selected and disabled, how do I do it?

  • Please ask your question again, not understandable what you want... – Marc Apr 02 '19 at 15:32
  • I think you are looking for this question: https://stackoverflow.com/questions/155291/can-html-checkboxes-be-set-to-readonly – imposterSyndrome Apr 02 '19 at 15:35
  • @jameson2012 yes but not with html, because it s easy to pass, only php –  Apr 02 '19 at 15:40
  • What do you mean, not with html? How do you expect the phone script to know what was submitted without html? I would second @Marc and say you need to re-write your question – imposterSyndrome Apr 02 '19 at 16:41

2 Answers2

0

As you have discovered, when you disable the element, it is not sent to the server.

There are a couple of things you could add to the element that would prevent user interaction. One is the style property pointer-events and the other is the element attribute tabindex

If the input element has style property pointer-events: none, the user cannot access it with mouse click (or touch). WARNING: If the input has a label, the label is "clickable" too, in that case, suggest wrapping both in a <div> with that style property.

That will prevent the user from directly interacting with the element, but there is always tab. Use tabindex=-1 so that the checkbox does not "participate in sequential keyboard navigation".

DinoCoderSaurus
  • 6,110
  • 2
  • 10
  • 15
0

Having read at Dino's answer I realise what you mean (I think). The simplest way to do that is to display the checkbox as checked and disabled then add a hidden input with the correct name and value, that way the user cannot interact with the checkbox, but the value is sent back to php in the form submission. If this isn't what you mean then you do need to re-write your question

imposterSyndrome
  • 896
  • 1
  • 7
  • 18