Using preEdit, keep getting this error undefined index: staff_kdu

Using preEdit, keep getting this error undefined index: staff_kdu

kkutikkuti Posts: 13Questions: 5Answers: 0
edited January 2021 in Free community support

The last section with preEdit, I have been unable to identify what the issue is, keeps giving undefined index: staff_pass.
Am trying to ensure that the password field is not changed when the record is been edited.

Editor::inst( $db, 'kdu_staffs', 'id' )
    ->fields(
        Field::inst( 'serial_number' ),
        Field::inst( 'name' )
            ->validator( Validate::notEmpty() ),
        Field::inst( 'email' ) 
            ->validator( Validate::notEmpty() )
            ->validator( Validate::unique(ValidateOptions::inst()
            ->message( 'Email address must be unique' )) ),
        Field::inst( 'status' )
            ->options(Options::inst()
            ->table('lecturer_levels')
            ->value('name')
            ->label('name')
            ->order('name asc')
            ->where(function($q){
            $q->where('status','active','=');
            })
            )
            ->validator( Validate::notEmpty() ),
        Field::inst( 'faculty' )
            ->options(Options::inst()
            ->table('faculty')
            ->value('name')
            ->label('name')
            ->order('name asc')
            ->where(function($q){
            $q->where('status','active','=');
            })
            )
            ->validator( Validate::notEmpty() ),
         Field::inst( 'department' )
            ->options(Options::inst()
            ->table('department')
            ->value('name')
            ->label('name')
            ->order('name asc')
            ->where(function($q){
            $q->where('status','active','=');
            })
            )
            ->validator( Validate::notEmpty() ),
        Field::inst( 'programme' ),
        Field::inst( 'dob' ),
        Field::inst( 'birth_place' ),
        Field::inst( 'state' ),
        Field::inst( 'lga' ),
        Field::inst( 'staff_pass'),
        Field::inst( 'created_by' )->set( Field::SET_EDIT ),
        Field::inst( 'created_date' )->set( Field::SET_EDIT ),
        Field::inst( 'created_by' )->setValue( $_SESSION['userlog']),
        Field::inst( 'created_date' )->setValue( date('Y-m-d H:i:s', strtotime('now')) )
    )
    ->on( 'preCreate', function ( $editor, $values ) {
        $xxlength = 10;
        $xxdata = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcefghijklmnopqrstuvwxyz';
        $kdu_pass = substr(str_shuffle($xxdata),0,$xxlength);
        $editor
            ->field( 'staff_pass' )
            ->setValue( $kdu_pass );
    } )
     ->on( 'preEdit', function ( $editor, $values ) {
        $editor
            ->field( 'created_by' )
            ->setValue( $_SESSION['userlog'] );
    } )                                                    
   ->on( 'preEdit', function ( $editor, $id, $values ) {
    if( $values['staff_pass'] === '' ) {
        $editor->field( 'staff_pass' )->set( false );
    }
    } )
    ->process( $_POST )
    ->json();

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Answer ✓

    I'm going to guess you are using inline editing? If so, then by default Editor will submit only the data for the cells which have been edited. So you could change your condition to be:

    if (isset($values['staff_pass']) && $values['staff_pass'] === '') {
      ...
    }
    

    Another option is to have Editor submit the whole form of data, regardless of what has changed - and example of which is available here.

    Allan

  • kkutikkuti Posts: 13Questions: 5Answers: 0

    Allan Thanks very much, that has solved the problem. I was not using inline editing however. Mighty grateful

This discussion has been closed.