RSjoomla! - Quality Joomla! Components

My Account






Lost Password?
No account yet? Register

Newsletter Subscribe

If you would like to be one of the first people to hear about the release of our new components then make sure you have subscribed to our announcements list! We won't bug you with unnecessary stuff.




RSform! Logo User Guide
RSform! - Form management component » RSform! Custom scripts and customization examples

RSform! Custom scripts and customization examples 

You can find here customization scripts for your forms.

Simple calculation with RSform! [Read All]

In this tutorial we will describe how to perform some field calculations in RSform! and displaying the result in the "Thank you !" message.

You can start by creating a new form called "Calculation". We will need to add 4 fields with the following settings:

1. Field id : Field1, Field Title : field1, Validation : numeric, Field Type : Text
2. Field id : Field2, Field Title : field2, Validation : numeric, Field Type : Text
3. Field id : total, Field Type : hidden
4. Field id : Field4, Field Title : calculate, Field Type : submit button,
Additional attributes:
onclick="document.getElementById('total').value = parseInt(document.getElementById('Field1').value) + parseInt(document.getElementById('Field2').value);"

On the "Thank You" tab please edit the Thank You message:
The result of the calculation is: {total}
Note: Field id is Case Sensitive. 

Mapping form submission on another external table [Read All]

Here's an example of how you could map the submission values of your form to an external database. Note that this example uses an external database.

Let's assume that your form contains the following fields(listed are the field ids):

  • firstname
  • lastname
  • email
  • phone
  • city
  • country
And you want to map them over an external database table.

Edit your form, go to the Scripts tab, and in the Scripts called on form process, type this code:

 //first we make sure that the code is triggered upon submission  

if(isset($_POST['form']['email'])) {
$database2 = $database;
$database2 = new database( 'host', 'user', 'password', 'db', 'prefix(if any)' );//comment this line if you're using the same db where the rsform tables are
$database2->setQuery("INSERT INTO `my_external_table` (`firstname`,`lastname`,`email`,`phone`,`city`,`country`) VALUES ('{$processform['firstname']}', '$processform['lastname']', '$processform['email']', '$processform['phone']', '$processform['city']', '$processform['country']')");
$database2->query();
}

Populate Select List from external tables [Read All]

In order to populate a selectbox field with values taken from an external table, you'll have to paste this script in the Scripts called on form Display, and change col1, col2 and my_external_table to match your needs.

 

foreach($fields as $i=>$field){
    if($field->name=='select1'){
        $database->setQuery("SELECT col1 as val, col 2 as txt FROM my_external_table");
        $values = $database->loadObjectList();
        $default_value = array();
        foreach($values as $row){
            $default_value[]= $row->val.'|'.$row->txt;
        }
        $default_value = implode(',',$default_value);
        $fields[$i]->default_value = $default_value;
    }
}