The Scripts Tab

The scripts tab is very useful for integrating RSform! with some external application. This should be used by experienced programmers only.

The Script called on form display is a php code that you can run whenever the form is displayed. You could auto-populate a selectbox with usernames for instance. 

The Script called on form process is a php code that you can run whenever the form is processed. This means that this script will run on form display also. If you want to trigger it only when the submit button is pressed, you should put it all under the condition:

 if(isset($_POST['form'])){

    your php code 

 }

Note that PHP scripts must be added without

 

Script called on form display

Here's an example of how you can get the users and load them in a select box (field id = select1):

Edit your form, go to Scripts and paste this code in

Script called on form display :

$database->setQuery("SELECT username FROM #__users");
$data = $database->loadObjectList();//we load the usernames

foreach($fields as $i=>$field){
   if($field->name=='select1'){//cycle through the fields, and find our select box field
       $string = array();
       if(!empty($data)){
           foreach($data as $data_row){
                //prepare the default syntax which will be value1|label1,value2|label2
               $string[] = $data_row->username.'|'.$data_row->username;
           }
       }
       $string = implode(',',$string);
       $fields[$i]->default_value = $string;
   }
}

Script called on form process

This script will be called whenever someone processes the form. Take a look at the Custom Scripts and customization examples chapter .

Was this article helpful?

Yes No
Sorry about that