What are scripts and pieces? I have seen them in the advanced form settings but I have no idea what they do.
Form Pieces Tab
==> Before Form: PHP that should be executed before the form is rendered. You can for example print something out and it will be displayed on top of the form.
==> After Form: The same like above but will be executed after the form is rendered. So printing will happen in the end of the form.
Submit Pieces Tab
==> Before Submit: PHP that will be executed before the form is going to be submitted. You can use this for example catching values and prevent storing a submission.
==> After Submit: Same like above, except that it will be executed after a submission has been stored.
*NOTE: Do not use opening PHP tags <?php in the pieces sections, else you will get errors!
All of these tabs above share the same concept:
- Library: You can choose a predefined script/piece from the library. While each item of the library can be packaged itself. Means, you can create your own library items and re-use them in other forms.
Things you always want to use in a Piece (PHP):
ff_getSubmit('FIELDNAME') => will return the value of a field
ff_getSubmit('FIELDNAME', FF_ARRAY) => will return the value of a field as array. Required if you want access to values of a group like a checkbox
As soon as you use things like ff_getSubmit() in your piece, put this as first command into your custom code:
$this -> execPieceByName('ff_InitLib');
ff_getElementByName('FIELDNAME') ==> will return the DOM object of the field
ff_getElementByName('FIELDNAME').value ==>will return the value of that field
The same is applicable for scripts that you use for validations, actions and initializations on field level.