How to fill a field value from the server side (newbie)

How to fill a field value from the server side (newbie)

luisrortegaluisrortega Posts: 79Questions: 6Answers: 1
edited January 2014 in Editor
Hi,

I have a table that during insertion I'll like to set a field (from the server side). Be aware that the client side it's not aware at all of this value.

[code]
$editor = Editor::inst( $db, 'completiontypes' )
->field(
Field::inst( 'id' )->set( false ),
Field::inst( 'name' )->validator( 'Validate::required' ),
Field::inst( 'company')// <--- this field needs to populated with a value stored on the server side
);
[/code]

Replies

  • allanallan Posts: 61,920Questions: 1Answers: 10,152 Site admin
    What you can do is:

    [code]
    if ( isset( $_POST['action'] ) && $_POST['action'] === 'create' ) {
    $_POST['data']['company'] = 'myValue';
    }
    [/code]

    drop that in before the Editor PHP instance is initialised and the data that it processes will then have the value needed. If you don't want to manipulate the _POST array (probably a good idea not to), just copy it to a new array (i.e. `$data = $_POST` ) beforehand.

    Regards,
    Allan
  • luisrortegaluisrortega Posts: 79Questions: 6Answers: 1
    This worked perfectly! tks!
  • luisrortegaluisrortega Posts: 79Questions: 6Answers: 1
    I'm guessing that if I want to do any data validation from the server side, here is where I would trap it?
This discussion has been closed.