Forums

Setting field values in Custom Code action

abletech 20 Sep, 2011
Hi, is there any (supported) way to set form field values, inside a Custom Code action, put in the OnLoad event?

I've tried this but cannot find what properties of the $form object should I set.

Finally I've solved putting my code in a Custom Element, that initialize a my own array, and setting the default value of fields with the form <?php echo $array['name']; ?>. I found this solution in this post (thank you!):
How to automatically fill out fields for registrated users

PS: there is documentation how to access the $form object inside Custom Code?
GreyHead 20 Sep, 2011
Hi Abletech,

If you want to set a static value then you can do that in the element configuration. If it's a dynamic value then you can set it in the $form->data array* using Custom Code (or another action) in the OnLoad event before theShow HTML action.

The format is $form->data['input_name']

Bob

* The code will work with either an array or an object but as the array is more widely used through ChronoForms it's probably tidier to use that format.
abletech 20 Sep, 2011
Thanks! It was easier that I thought.

I choose ChronoForms (and buy the license) over other solutions, because of this very high flexibility.

What about explaining this $form->data array also in the Help tab of Custom code action? Now it is the help, referring only to $form->form_output.

You may use PHP code with php tags.
Running this as Controller is required if you want to do some data processing for some serverside stuff like sending emails, uploading files, saving data or even processing some payment gateway response.
Running this as View is "advised" if you want to output some data, like any kind of HTML, it depends on when and where you want this data displayed and on which other actions do you have.
the variable $form->form_output is available for use at both modes, it holds the form view output up to the moment of running this action.

GreyHead 21 Sep, 2011
Hi abletech,

It would be good to improve the Help pages. I can't directly change them though :-(

Bob
This topic is locked and no more replies can be posted.