⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Custom error message



dblanco

dblanco
  • profile picture
  • Member

Posted 07 December 2012 - 21:38 PM

I want that when the system can not insert a record, the message indicated report at runtime.

Using the following code does not work:

$this->grocery_crud->callback_insert(array($this,'_insertar_registro'));

function _insertar_registro($post_array) {
... control data with error....

$this->grocery_crud->set_lang_string('insert_error', 'No inserto');
return FALSE;
}

Displays on screen: 'Ocurrio un error durante la insercion.'

because in the selected language file is indicated:

$lang['insert_error'] = 'Ocurrio un error durante la insercion.';

but not the message specified by the function insertar_registro.

What's wrong? thanks

pquesadacr

pquesadacr
  • profile picture
  • Member

Posted 13 December 2012 - 15:16 PM

Hi,
Did you resolve something on this? I need to do something similar (custom message for insert).

dblanco

dblanco
  • profile picture
  • Member

Posted 13 December 2012 - 22:52 PM

No, set_lang_string not work.

dblanco

dblanco
  • profile picture
  • Member

Posted 03 January 2013 - 15:14 PM

Looking at the generated html, I find that this fixed the error message in the variable message_insert_error:

<script>
var validation_url = 'http://localhost/admin/sucursales_horario/grilla/1/insert_validation';
var list_url = 'http://localhost/admin/sucursales_horario/grilla/1';

var message_alert_add_form = "Los datos que insertaste no pueden ser guardados.\nEstas seguro que quieres regresar a la lista?";
var message_insert_error = "Ocurrio un error durante la insercion.";
</script>
Is there any way to modify it at runtime? (for example using set_lang_string)

dblanco

dblanco
  • profile picture
  • Member

Posted 03 January 2013 - 18:25 PM

I solved it by jquery, changing the contents of the variable message_insert_error dynamically.

thanks

orochimaru

orochimaru
  • profile picture
  • Member

Posted 13 March 2013 - 12:58 PM

can you post a sample of your jquery code please  ;)


dblanco

dblanco
  • profile picture
  • Member

Posted 13 March 2013 - 13:06 PM

Jquery is:

 

        <script type="text/javascript">
        //cuando el navegador esté listo
        $(document).ready(function(){
            var base_url        = '{ruta_url}';
            var accion            = '{accion}';

            $("#field-id_horario").change(function(evento){
                var id_sucursal                    = $("#field-id_sucursal").val();
                var id_horario_seleccionado      = $(this).val();
 
                if (accion == 'add') {
                    // alta
                    $.get(base_url+"admin/sucursales_horario/actualiza_mensaje/"+id_sucursal+"/"+id_horario_seleccionado,
                            {
                            },
                            function(datos) {
                                message_insert_error = datos;
                            }        
                    );        
                }
                
                if (accion == 'edit') {
                    // modificacion
                    if (id_horario_seleccionado != {id_horario_old}) {
                       // cambio clave
                        $.get(base_url+"admin/sucursales_horario/actualiza_mensaje/"+id_sucursal+"/"+id_horario_seleccionado,
                                {
                                },
                                function(datos) {
                                    message_update_error = datos;
                                }        
                        );            
                    }
                }
           });
        });
        </script>

 

In controller:

 

    /*********************************************
    * Funcion llamada por jquery                 *
    * controla ducplicidad, para cambiar mensaje *
    * Parametros:                                *
    * id_sucursal                                *
    * id_horario                                 *
    *********************************************/
    function actualiza_mensaje($id_sucursal, $id_horario) {
        $esta_logueado     = $this->autorizacion->_esta_logueado();    
        if (!$esta_logueado) {
            // no esta logueado
            redirect('admin/logout', 'location');
         } else {
            $datos = array(
                        'id_horario'     => $id_horario,
                        'id_sucursal'     => $id_sucursal,
                    );
            $existe_horario = $this->sucursales_horario_model->_existe_horario($datos);
            
            if ($existe_horario) {
                echo "Ya existe el horario seleccionado para la sucursal.";
            } else {
                echo "Ocurrio un error al querer actualizar la base.";
            }
        }
    }


orochimaru

orochimaru
  • profile picture
  • Member

Posted 13 March 2013 - 13:10 PM

wow blazing fast response  :o

thanks you very much man