This topic is locked
[SOLVED]

 Override database value in edit field using $xt

1/10/2010 4:52:31 PM
PHPRunner General questions
A
alang author

I have a field in a table which defines a physical storage location - file reference number. By default it is set to zero when the record is created. When I go to the edit page, I would like to calculate a suggested number and have that populate the field on the edit page, only if the database value is zero. Can I do this using $xt in the "Before Display" event code? (PHPR V5.2beta)
Something like:



if($xt->xt_vars["value_fileref"])

$xt->assign("value_fileref",$mynewvalue)


  • I don't want to use autoincrement set in database
  • I don't want to assign default value when the record is created
  • I could use the "Before SQL query" event code to set a default value but this is not preferred in case the edit is cancelled - I would need to rollback the database update.

A
alang author 1/11/2010

Note that the first code line should read if(!$xt->xt_vars["value_fileref"]) to match my description.
Also, a variation of the third option mentioned above does work OK. ie in the Before SQL query, set a session variable which can then be referenced in the default field on the visual editor properties for that field.
In any case, I am still curious as to whether it can be done with $xt as requested.
Thanks.

J
Jane 1/12/2010

Hi,
here is a sample code for Before display event:

global $control_FieldName;

if (!$control_FieldName["params"]["value"])

$control_FieldName["params"]["value"]=$mynewvalue;
A
alang author 1/13/2010

Thanks for that Jane - I see how it works now. Rather than using the global, it is also possible to use the $xt variable for others interested.



if(!$xt->xt_vars["MyFieldName_editcontrol"]["params"]["value"])

$xt->xt_vars["MyFieldName_editcontrol"]["params"]["value"]=$mynewvalue;