preCreate insert a value to a field NOT sent to client side?
preCreate insert a value to a field NOT sent to client side?
I've got an administrator page where the admin can edit users data and create/delete user. The admin can not see, change or create new password for the user. Instead, when creating a new user, a dynamically generated password is generated server side and inserted together with all the other data.
My problem is I don't want the password field being sent to the client, and I haven't found a way to use preCreate without including user password field in the select when getting the users data from the database.
See below. The preCreate works fine and will generate a hash that's inserted with other data. (of course the 'qwe234' below is just for testing). The problem is I need to include the first field user_pwd that gets sent to the client. And even if I don't show it, it is easily viewed thru Firefox network console...
Is there a way to insert a value with preCreate without having that field included in the Ajax sent to client? I could empty that field before sending it, but then if user is Updated the original password will get messed up?
```
// DataTables PHP library
include( "../php/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
/*
* Example PHP implementation used for the join.html example
*/
Editor::inst( $db, 'users', 'user_id' )
->field(
Field::inst( 'users.user_pwd' ),
Field::inst( 'users.user_employee' ),
Field::inst( 'users.user_fname' ),
Field::inst( 'users.user_lname' ),
Field::inst( 'users.user_nickname' ),
Field::inst( 'users.workteam_id' )
->options( 'workteam', 'workteam_id', 'workteam_name' ),
Field::inst( 'workteam.workteam_name' ),
Field::inst( 'users.workdesc_id' )
->options( 'workdesc', 'workdesc_id', 'workdesc_name' ),
Field::inst( 'workdesc.workdesc_name' )
)
->leftJoin( 'workteam', 'workteam.workteam_id', '=', 'users.workteam_id' )
->leftJoin( 'workdesc', 'workdesc.workdesc_id', '=', 'users.workdesc_id' )
->join(
Mjoin::inst( 'roles' )
->link( 'users.user_id', 'permissions.user_id' )
->link( 'roles.role_id', 'permissions.role_id' )
->order( 'role_desc asc' )
->fields(
Field::inst( 'role_id' )
->validator( 'Validate::required' )
->options( 'roles', 'role_id', 'role_desc' ),
Field::inst( 'role_desc' )
)
)
->on( 'preCreate', function ( $editor, $values ) {
$editor
->field( 'users.user_pwd' )
->setValue(password_hash('qwe234', PASSWORD_DEFAULT));
} )
->process($_POST)
->json();
```