I'm using another way that works for me :
Serialize form data (as specified above, will exclude unchecked'valuescheckboxes' values that are unchecked) :
const formData = $("form[name='config']").serialize();
const data = {
config: formData
}
Then, in PHP, I'm building a JSON object :
parse_str($_REQUEST['config'], $configJSON);
$configJSON = json_encode($configJSON);
And in MSSQL, in my stored procedure when a column is missing from the JSON (because it's been filtered out by the jquery serialization) it will be NULL and so will be replaced by 0 (thanks to ISNULL
function) :
ALTER PROCEDURE [dbo].[eth_userprofil_updateconfig]
(
@userId int,
@configJSON nvarchar(max)
)
AS
BEGIN
SET NOCOUNT ON;
UPDATE dbo.MyTable
SET MyField = ISNULL(JSON_VALUE(@configJSON, '$.MyField '), 0),
....
WHERE userId = @userId
END