0

Let's say I have an HTML form with various fields and a checkbox. After checking the checkbox the user submits the form (checkbox database in value becomes true). After the submit I made it so the checkbox becomes disabled.

Later on the user enters the form again and makes other changes to the form, except from the checkbox (that he can't use cause it's gray). What happens if he submits? Does the checkbox value change in the database to a default value (true or false) because it's disabled or does it retain the value from the first submission.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • What happened when you tried it? – mjwills Jan 18 '19 at 19:53
  • Well it retained the value from the first submit. I'm just worried because a friend of mine disabled a text field in the same form, and every submit afterwards deleted the text entirely from the database. But that doesnt happen with the checkbox – Kresto Kidd Jan 18 '19 at 19:58
  • 1
    You are conflating two issues. There are two things you need to think about. a) How does disabling a field impact the data that is POSTed to the server? This can be checked easily using Chrome Developer Tools. b) What does your server side do if some of the data is not passed up? Obviously your code, and your friend's code, handle that differently. We can't assist you with that for the simple reason that you haven't showed us the code. – mjwills Jan 18 '19 at 20:05
  • I would have thought this would be easy to determine by writing a small test case and see how it works. Your question should include examples of what you've tried and what hasn't worked for you. Knowing you are just using MVC, jQuery, C# and html doesn't provide us with enough information. – Chris Walsh Jan 18 '19 at 21:52

1 Answers1

2

A disabled element will not be included in the request, hence the answer to your question is entirely down to how your server side logic handles the form submission.

It will either fail validation (if the field is required), it will assume a default state of false for the missing boolean value and update it in the database, or it will detect the lack of a value and not update the database field at all.

In any scenario this isn't a JS concern and needs to instead be handled by you in your, judging by the tags, C# MVC logic.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339