Variable on ADD
Variable on ADD
nskwortsow
Posts: 120Questions: 0Answers: 0
Hi,
When adding a record I need to insert the OwnerID (parent table). Should I use a HIDDEN field for this? If so: how do I insert the current session['OwnerID'] in the javascript (I use external .js libraries and don't like to mix PHP and JS).
Seems cumbersome to populate with a $('#OwnerID').val(); but if I have to, I will. Please point me in the right direction.
/N
When adding a record I need to insert the OwnerID (parent table). Should I use a HIDDEN field for this? If so: how do I insert the current session['OwnerID'] in the javascript (I use external .js libraries and don't like to mix PHP and JS).
Seems cumbersome to populate with a $('#OwnerID').val(); but if I have to, I will. Please point me in the right direction.
/N
This discussion has been closed.
Replies
Allan
Thanks, but please be more specific when it comes to the server side processing. I don't want to write my own code in parallel to your API if I can help it (gets messy).
I can set the value, no problem, but when I send it for CREATING, what does my PHP look like?
[code]
$editor = Editor::inst( $db, 'browsers' )
->fields(
Field::inst( 'name' )->validator( 'Validate::required' ),
Field::inst( 'dept' )->validator( 'Validate::required' )
);
if ( isset($_POST['action']) && $_POST['action'] === 'create' ) {
// Adding a new record, so add a field that will be written
$editor->field( Field::inst('owner') );
$_POST['data']['owner'] = $_SESSION['id'];
}
else {
// Otherwise editing, deleting or getting data. Just read the owner field
$editor->field( Field::inst('owner')->set(false) );
}
$editor
->process( $_POST )
->json();
[/code]
The key thing here is that the fields for the Editor instance don't need to be static - they can be dynamically built - as is the case above.
Allan