Get Editor Field Value in Server Side

Get Editor Field Value in Server Side

karim.rezegkarim.rezeg Posts: 1Questions: 1Answers: 0
edited June 2015 in Free community support

Hello everyone,
I am trying to get the value of a field in an Editor instance in order to execute another query after every insert/update action, but I am constantly getting the following error message "A system error has occurred" .
I already tried different ways to get the variable, like this one:

use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Join,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate;

    


$editor=Editor::inst( $db, 'budgets' )
    ->fields(
        
                Field::inst( 'block' )
                    ->setValue( $block ),
                Field::inst( 'currency' )->setValue( 'EUR' ),
                Field::inst( 'kfw' )->validator( 'Validate::numeric' , array('required' => true)),
                Field::inst( 'uni_hh' )->validator( 'Validate::numeric' , array('required' => true)),
                Field::inst( 'amount' ),
                Field::inst( 'block_position' )->options( $positions_table, 'block_position', 'definition' )->validator( 'Validate::notEmpty' ),
                
                Field::inst( 'definition' ),
                Field::inst( 'comments' ),
                Field::inst( 'office' )
                    ->setValue( $office ),
                Field::inst( 'project' )
                    ->setValue( $project )
                
            )
            ->where('project', $project)
            ->where('office', $office)
            ->where('block', $block);

$data=$editor->process( $_POST )
            ->data();


if ( (isset( $_POST['action'] )) && ($_POST['action'] !== 'delete') ) {
    $text=$data['definition'];
    $update= $db->sql("UPDATE `budgets` SET `comments`='$text' WHERE `project`='0'");
    
}

echo json_encode( $data );

and this one:

if ( (isset( $_POST['action'] )) && ($_POST['action'] !== 'delete') ) {
    $text=$_POST['data']['definition'];
    $update= $db->sql("UPDATE `budgets` SET `comments`='$text' WHERE `project`='0'");
    
}


The Editor instance and the query are working, but I am failing to get the "definition" value and I am still getting the error message after every action. I just don't know how to access the chosen values of the editor fields in PHP.

Answers

  • allanallan Posts: 61,903Questions: 1Answers: 10,148 Site admin

    "A system error has occurred"

    That means that the data returned from the server is not valid JSON. If you use your browser's developer tools to look at the Ajax request's data, what does it show as being returned?

    Allan

This discussion has been closed.