wpdatatables_before_frontend_edit_row

Contents

Description

This action is executed before the editing action is applied. It can be used for validation.

Usage

add_action( 'wpdatatables_before_frontend_edit_row', 'input_validation', 10, 3 );

Parameters

  • $formData array
    Array of entries from front-end.
  • $returnResult array
    Array of result messages.
  • $tableId array
    Identifier of the table from MySQL.

Examples

// Callback function for the wpdatatables_before_frontend_edit_row action hook
function input_validation( $formdata, $returnResult, $tableID) { 
    // Provide id for your table where you need validation,
    // we insert 1 as example
    if ($tableID == 1) {
        // You will replace orig_header with your real name of orig_header
        // which you can find it in column settings, and also a condition
        // this is checker for specific column
        if ($formdata['orig_header'] == ''){
            // You can provide your custom error message
            $returnResult['error'] = __('Column name can not be empty', 'wpdatatables') ;
            echo json_encode($returnResult);
            exit();
        }
        // $formdata is array so you can also create a loop if you need
        // to go throw all form data entries and check if they pass your condition
        //        foreach ($formdata as $signleEntry){
        //            if ($signleEntry == 'your condition'){
        //                $returnResult['error'] = __('Your custom error message', 'wpdatatables') ;
        //                echo json_encode($returnResult);
        //                exit();
        //            }
        //        }
    }
}

add_action( 'wpdatatables_before_frontend_edit_row', 'input_validation', 10, 3 );