Create/Edit record using userid in PHP variable in DB column
Create/Edit record using userid in PHP variable in DB column
peterbrowne
Posts: 314Questions: 54Answers: 0
I have DB columns 'updated_by' and 'created_by' where the DataTables userid (logged-in user) needs to be recorded automatically.
The userid is stored in a PHP variable $user
How can I put this variable value into those fields? The fields are not available in the editor, but show in DataTables.
Editor::inst( $db, 'user', 'user_pk' )
->fields(
Field::inst( 'user_id' ),
Field::inst( 'first_name' ),
Field::inst( 'last_name' ),
Field::inst( 'email' ),
Field::inst( 'user_type' ),
Field::inst( 'created' ),
Field::inst( 'created_by' ),
Field::inst( 'updated' ),
Field::inst( 'updated_by' )
)->process( $_POST )->json();
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
OK, I have changed the fields a bit and hidden the renamed fields as 'modified' and 'modified_by':
Still not updating the 'modified_by' column using the PHP variable captured via a hidden form element to a JQuery variable 'user_id'
and using:
You can use
Field->setValue()
for this - e.g.:Full API reference docs for PHP are available here.
Allan
Thanks again Allan! Also I needed to add session_start(); at the beginning of the server PHP editor script: