preEdit is not working

preEdit is not working

jcandelasjcandelas Posts: 2Questions: 1Answers: 0
edited June 2016 in Free community support

Hello guys,

I have the following code, but nothing happens with the preEdit event, I tried to put the "->on( 'preEdit', function ( $editor, $values )" before "->process( $_POST )", but with this I got the error "Contact Administrator":

Editor::inst( $db, 'candidatos' )
    ->fields(
        Field::inst( 'id_rocar' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'nombre' )
            ->validator( 'Validate::notEmpty', array(
                "message" => "Este campo es requerido"
            ) ) // This field is required
            ->validator( 'Validate::maxLen', array(
                                    'max' => 32,
                                    'message' => 'La entrada es muy larga, limítese a 32 catacteres, por favor'
                                )), // The input is 1 characters too long
        Field::inst( 'apellido_paterno' )
            ->validator( 'Validate::notEmpty', array(
                "message" => "Este campo es requerido"
            ) ) // This field is required
            ->validator( 'Validate::maxLen', array(
                                    'max' => 32,
                                    'message' => 'La entrada es muy larga, limítese a 32 catacteres, por favor'
                                )), // The input is 1 characters too long
        Field::inst( 'apellido_materno' )
            ->validator( 'Validate::maxLen', array(
                                    'max' => 32,
                                    'message' => 'La entrada es muy larga, limítese a 32 catacteres, por favor'
                                )), // The input is 1 characters too long
        Field::inst( 'genero' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'fecha_nacimiento' )
            ->validator( 'Validate::notEmpty' )
            ->validator( 'Validate::dateFormat', array(
                "format"  => "Y-m-d",
                "message" => "Por favor, inserte una fecha en el formato aaaa-mm-dd"
            ) ),
        Field::inst( 'email' )
            ->validator( 'Validate::notEmpty', array(
                "message" => "Este campo es requerido"
            ) ) // This field is required
            ->validator( 'Validate::email', array('message'=>"Por favor, inserte una dirección de correo válida") ) //Please enter a valid e-mail address 
            ->validator( 'Validate::maxLen', array(
                                    'max' => 64,
                                    'message' => 'La entrada es muy larga, limítese a 64 catacteres, por favor'
                                )), // The input is 1 characters too long
        Field::inst( 'telefono' )
            ->validator( 'Validate::notEmpty', array(
                "message" => "Este campo es requerido"
            ) ) // This field is required
            ->validator( 'Validate::numeric', array('message' => 'La entrada debe ser numérica, por favor') ) // This input must be given as a number
            ->validator( 'Validate::maxLen', array(
                                    'max' => 16,
                                    'message' => 'La entrada es muy larga, limítese a 16 catacteres, por favor'
                                )) // The input is 1 characters too long
            ->validator( 'Validate::minLen', array(
                                    'min' => 10,
                                    'message' => 'La entrada es muy corta, se requieren 10 catacteres, por favor'
                                )), // The input is too short. 18 characters required (2 more required)
        Field::inst( 'curp' )->validator( 'Validate::notEmpty', array(
                "message" => "Este campo es requerido"
            ) ) // This field is required
            ->validator( 'Validate::maxLen', array(
                                    'max' => 18,
                                    'message' => 'La entrada es muy larga, limítese a 18 catacteres, por favor'
                                )) // The input is 1 characters too long
            ->validator( 'Validate::minLen', array(
                                    'min' => 18,
                                    'message' => 'La entrada es muy corta, se requieren 18 catacteres, por favor'
                                )), // The input is too short. 18 characters required (2 more required)
        Field::inst( 'ciudad' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'pais' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'status' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'fecha_creacion' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'foto_archivo_id' )
            ->setFormatter( 'Format::ifEmpty', null )
            ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/rocar/production/candidatos_documentos/__ID__.__EXTN__' )
                ->db( 'files', 'id', array(
                    'filename'    => Upload::DB_FILE_NAME,
                    'filesize'    => Upload::DB_FILE_SIZE,
                    'web_path'    => Upload::DB_WEB_PATH,
                    'system_path' => Upload::DB_SYSTEM_PATH
                ) )
                ->validator( function ( $file ) {
                    return$file['size'] >= 110000 ?
                        "El archivo debe ser menor que 100K" :
                        null;
                } )
                ->allowedExtensions( [ 'png', 'jpg', 'gif' ], "Por favor cargue una imagen (jpg, png o gif)" )
            ),
        Field::inst( 'licencia_archivo_id' )
            ->setFormatter( 'Format::ifEmpty', null )
            ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/rocar/production/candidatos_documentos/__ID__.__EXTN__' )
                ->db( 'files', 'id', array(
                    'filename'    => Upload::DB_FILE_NAME,
                    'filesize'    => Upload::DB_FILE_SIZE,
                    'web_path'    => Upload::DB_WEB_PATH,
                    'system_path' => Upload::DB_SYSTEM_PATH
                ) )
                ->validator( function ( $file ) {
                    return$file['size'] >= 110000 ?
                        "El archivo debe ser menor que 100K" :
                        null;
                } )
                ->allowedExtensions( [ 'png', 'jpg', 'gif' ], "Por favor cargue una imagen (jpg, png o gif)" )
            ),
        Field::inst( 'curp_archivo_id' )
            ->setFormatter( 'Format::ifEmpty', null )
            ->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/rocar/production/candidatos_documentos/__ID__.__EXTN__' )
                ->db( 'files', 'id', array(
                    'filename'    => Upload::DB_FILE_NAME,
                    'filesize'    => Upload::DB_FILE_SIZE,
                    'web_path'    => Upload::DB_WEB_PATH,
                    'system_path' => Upload::DB_SYSTEM_PATH
                ) )
                ->validator( function ( $file ) {
                    return$file['size'] >= 110000 ?
                        "El archivo debe ser menor que 100K" :
                        null;
                } )
                ->allowedExtensions( [ 'pdf' ], "Por favor cargue un archivo PDF" )
            ),
        Field::inst( 'ultima_actualizacion_por' )->set( Field::SET_EDIT ),
        Field::inst( 'ultima_actualizacion_fecha' )->set( Field::SET_EDIT ),
        Field::inst( 'ultima_actualizacion_ip' )->set( Field::SET_EDIT )
            
        /*Field::inst( 'foto_archivo_nombre' )
            ->upload( Upload::inst(
                function ( $file, $id ) {
                    move_uploaded_file( $file['tmp_name'], 'candidatos_documentos/'.$file['name'] );
                    return 'candidatos_documentos/'.$file['name'];
                } )
              )*/
    )
    ->where( 'status', 'NUEVO' )
    ->process( $_POST )
    ->on( 'preEdit', function ( $editor, $values ) {
        $editor
            ->field( 'ultima_actualizacion_por' )
            ->setValue( $_SESSION['username'] );
        $editor
            ->field( 'ultima_actualizacion_ip' )
            ->setValue( "192.168.1.111" );
        $editor
            ->field( 'ultima_actualizacion_fecha' )
            ->setValue( date("Y-m-d H:i:s") );
    } )
    ->json();

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • jcandelasjcandelas Posts: 2Questions: 1Answers: 0

    Sorry, I found the error, "->on( 'preEdit', function ( $editor, $values )" goes before "->process( $_POST )" and my error is that $_SESSION['username'] does does not have a value ("")

  • allanallan Posts: 62,241Questions: 1Answers: 10,211 Site admin

    Thanks for posting back - great to hear you found the issue. You are absolutely correct - the process() method basically executes what has been setup, so the event handlers need to be added before it is called.

    Allan

This discussion has been closed.