Set value passthrough in $this->input->post in PHP

Asked

Viewed 77 times

0

good night I have the method below that adds filled values of a modal

public function ajax_add()
{

    $this->_validate();
    $data = array(
            'owner' => $this->input->post('owner'),
            'dpo' => $this->input->post('dpo'),
            'grupo' => $this->input->post('grupo'),
            'sub_grupo' => $this->input->post('sub_grupo'),
            'semana' => $this->input->post('semana'),
            'cod_id' => $this->input->post('cod_id'),
            'atividade' => $this->input->post('atividade'),
            'obj_esperado' => $this->input->post('obj_esperado'),
            'alcancado' => $this->input->post('alcancado'),
            'conc_esti' => $this->input->post('conc_esti'),
            'anl_envolvidos' => $this->input->post('anl_envolvidos'),

    );
    $insert = $this->projeto->save($data);
    echo json_encode(array("status" => TRUE));

However, I need to pass two more fixed values on this addition that will be:

    'operacao' => $this->input->post("INS"),
    'data_reg' => $this->input->post(NOW()),

This will serve to include which operation is being done and the date. These values will not come from FORM MODAL, they will have to be fixed.

My add or update ajax, this so:

function save()
{
$('#btnSave').text('salvando...'); //change button text
$('#btnSave').attr('disabled',true); //set button disable 
var url;
  if(save_method == 'add') {
    url = "<?php echo site_url('projeto/ajax_add')?>";
} else {
    url = "<?php echo site_url('projeto/ajax_update')?>";
}

// ajax adding data to database
$.ajax({
    url : url,
    type: "POST",
    data: $('#form').serialize(),
    dataType: "JSON",
    success: function(data)
    {

        if(data.status) //if success close modal and reload ajax table
        {
            $('#modal_form').modal('hide');
            reload_table();
        }
        else
        {
            for (var i = 0; i < data.inputerror.length; i++) 
            {

   $('[name="'+data.inputerror[i]+'"]').parent().parent().addClass('has- 
   error'); //select parent twice to select div form-group class and add 
   has-error class

   $('[name="'+data.inputerror[i]+'"]').next().text(data.error_string[i]); 
   //select span help-block class set text error string
            }
        }
        $('#btnSave').text('save'); //change button text
        $('#btnSave').attr('disabled',false); //set button enable 


    },
    error: function (jqXHR, textStatus, errorThrown)
    {
        alert('Erro adicionando ou atualizando registro');
        $('#btnSave').text('save'); //change button text
        $('#btnSave').attr('disabled',false); //set button enable 

    }
   });
}

How could I do that ? I did some tests but without success.

Thank you very much.

  • And why you do not directly enter in the code these two fixed values?

  • But in what place Andrei? in the very ajax ?

  • 1

    Well, I solved the problem: it just went like this: 'operation' => ("INS"), 'data_reg' => $dataReg, in the PHP code and it worked. simple.

No answers

Browser other questions tagged

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