Field disabled does not pass to $ _POST

3

I have problems with the field that I disable if one of the options is checked, but when the field is as desabled it does not pass values to PHP.

I would like to know how to check whether the value exists or not, and if it does not exist, set it to null.

I tried to do in several ways but the same error happens:

  

PHP Notice: Undefined index: f_DAT_FINAL_VINCU

The attempts were:

   $campos[':DAT_FINAL_VINCU'] = ((isset($_POST['f_DAT_FINAL_VINCU'])) ? eglise_dataDeDMAParaAMD($_POST['f_DAT_FINAL_VINCU']) : null ); 
    $campos[':DAT_FINAL_VINCU'] = strlen(eglise_dataDeDMAParaAMD($_POST['f_DAT_FINAL_VINCU'])) === 0 ? null : htmlspecialchars($_POST['f_TXT_DESCR_VINCU'], ENT_QUOTES); 
    $campos[':DAT_FINAL_VINCU'] = strlen(eglise_dataDeDMAParaAMD($_POST['f_DAT_FINAL_VINCU'])) === null ? null : htmlspecialchars($_POST['f_TXT_DESCR_VINCU'], ENT_QUOTES); 

How do I do it?

I'm putting the field via jQUERY but it's not working looks like I do:

        var variavel = $('#f_FLG_STATU_VINCU').val();
    if (variavel == "A") {
        $('#f_DAT_FINAL_VINCU').val(null);
    }
    $('#f_FLG_STATU_VINCU').change(function () {

        var variavel = $(this).val();
        var today = new Date();

        if (variavel == "A") {
            $('#f_DAT_FINAL_VINCU').val(null);
            $('#f_DAT_FINAL_VINCU').prop("readonly", true);
        } else {
            $('#f_DAT_FINAL_VINCU').prop("readonly", false);
            $('#f_DAT_FINAL_VINCU').datepicker("setDate", today);
        }
    });
    
asked by anonymous 22.01.2016 / 16:16

1 answer

3

That way the treatment will work:

 $campos[':DAT_FINAL_VINCU'] = array_key_exist('f_DAT_FINAL_VINCU',$_POST) && $_POST['f_DAT_FINAL_VINCU'] !== null ? eglise_dataDeDMAParaAMD($_POST['f_DAT_FINAL_VINCU']) : null ; 

In this ternary we are checking if the key exists in the array, if it exists, it checks if the value is not NULL.

Remember that whenever you receive HTML parameters you should perform a treatment such as "htmlspecialchars" or "htmlentities" to avoid attacks like sql injection or similar.

    
22.01.2016 / 17:20