Disabled field does not pass to $_POST

Asked

Viewed 177 times

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 to null.

I tried to make several ways but the same mistake happens:

PHP Notice: Undefined index: f_DAT_FINAL_VINCU

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 should I do ?

I’m putting the field via jquery but it’s not working look how 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);
        }
    });
  • readonly passa disabled already says field disabled

  • 2
  • Still not working, look at my edition

  • @rray how will my $fields['] array look? Because if the value is empty you need to set it to null

  • 1

    Check whether the array element or the inner array is empty: if(empty($array)) or if(empty($array['posicao'])) and arrow like null

  • Vlw, it worked out !

Show 1 more comment

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 ternario we are checking if the key exists in the array , existing it checks if the value is not NULL.

Remembering that whenever receiving HTML parameters one should perform a treatment like "htmlspecialchars or "htmlentities" to avoid attacks like sql Injection or similar.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.