onBeforeInsert generating table value

Discussion in 'Developers' Forum' started by mare, Jan 14, 2013.

  1. mare

    mare New Member

    Hello,

    I use onBeforeInsert in my table_edit.php to generate a value which should be added to the database (will come from another subsystem so it's not available during the form input).

    currently i do the following but thing there is a better solution .

    Code:
    function onBeforeInsert()
                {
                  global $app 
                  $app->tform->errorMessage = myfunction($_POST) ;
                  $this->dataRecord['value'] = $_SESSION['value'] ;
                  unset ($_SESSION['value']) ;
    }
    
    Code:
    myfunction($_VAR) 
    {
    global $_SESSION ;
    ...
    if (ok) 
    $_SESSION['value'] = "foo";
    (else)
    return "error foo :-(" ;
    }
    
    
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    May you describe a bit more what you try to do. ISPConfig has various methods to validate and filter user input incl. custom validators and custom datasources for values. A custom validator or custom datasource is a php class which can handle nearly any kind of value and the validators and datasources are just configured in the tform file, there is no overriding of onBeforeInsert nescessary then.
     
  3. mare

    mare New Member

    I have a form with Value A and B

    What i tried to find out was how to :

    Entering Value A into a form --> submit the form --> use onBeforeInsert function in myform_edit.php to generate Value B and store this into the table.

    So Value B is not entered by the user but generate by ispconfig.

    I found that i simply can use $page->dataRecord['B'] = $result['object'] ; to fill B.
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    Yes, thats correct. If B is defined in the tform file as table field, you can set B in dataRecord in any event function that gets executed before the insert or update happens.
     

Share This Page