Accessing row data in preEdit in PHP

Accessing row data in preEdit in PHP

rw152rw152 Posts: 56Questions: 15Answers: 1
edited November 2016 in Free community support

I have some values for a row that I use in my PHP file to inst them, but I purposely don't allow them to be in the editor, even if they are locked because I don't want the user to hijack the ajax request on edit and alter the value.

How can I access a value like this on preEdit? For example, it's really easy to access the data being sent from the server in the ajax call, but how can I access the data about the row that is not being sent up in the ajax call?

Example code:

Field::inst( 'tblExample.isExample' )
    ->set( false )

.....

 ->on( 'preEdit', function ( $editor, $id,$values ) {
    //here is where you can pull values easily, like $example = $values['tblExample']['example'];
   // but how can I pull values not in the $values variable? When I var_dump the $editor variable, I cannot see how to grab the values since they are private.

//GOAL: get tblExample.isExample value
}

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin
    Answer ✓

    but how can I access the data about the row that is not being sent up in the ajax call?

    You'd need to query the database to get it. The $values array only contains the information submitted by the client-side.

    You could use something like:

    $row = $editor->db()->select( 'tableName', 'fieldName', array( 'id' => $id ) );
    

    To get the information from the database.

    Allan

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    Posted in error- sorry.

This discussion has been closed.