Indhold
Codesnippets for RSForm Pro
Usefull code-snippets for the Joomla! Component RSForm Pro.
All examples below are snippets i have used in different projects.
Open calendar on specific month
PHP-Script - $formLayout
$replace = "extra: Array({'mindate': '01/06/2015'},{'mindate': '01/06/2015'})";
$with = "extra: Array({'mindate': '06/06/2015', 'pagedate': '06/2015'}, {'mindate': '06/06/2015', 'pagedate': '06/2015'})";
$formLayout = str_replace($replace, $with, $formLayout);
Check if textfield contains both first and lastname
PHP-Script - $_POST
if (count(str_word_count($_POST['form']['Navn'], 1)) < 2)
$invalid[] = RSFormProHelper::getComponentId("Navn");
Clear fields value if other field is changed
Javascript-Script
//CLEAR ALL EDUCATIONNAMES ON EDUCATIONTYPE CHANGE
jQuery('select#education_type').on('change', function (){
jQuery('select.edu').val(0);
});
Clear fields value if other field is changed
Javascript-Script
jQuery('select.edu').on('change', function ()
{
// GET THE OPTION GROUP VALUE FROM SELECTBOXES
var omraade = jQuery(this.options[this.selectedIndex]).closest('optgroup').prop('label');
jQuery('input#omraade').val(omraade);
});
Save value from one field to another
Javascript-Script
jQuery("input#utelefon").blur(function(){
// Get the value from utelefon
var telefon = jQuery( "input#utelefon" ).val();
// Set hiddenfield value
$("input#hiddenvalue").val(telefon);
});
Display exampletext in field placeholder
Field attributes & PHP-Script $_POST
Place the code below on a textfield or textarea in 'Additional Attributes' to display a example in the placeholder.
onfocus="if (this.value=='(eksempel) 2Y') this.value='';"
onblur="if (this.value=='') this.value='(eksempel) 2Y';"
To prevent the user from submitting the form with the 'example-text' - use the PHP-script below:
$klasse= $_POST['form']['klasse'];
if ($klasse == "(eksempel) 2C" ) {
$invalid[] = RSFormProHelper::getComponentId("klasse");
}
else{
return true;
}
Check if field value exists in array
PHP-Script $_POST
$fieldvalue= $_POST['form']['THEFIELDNAME'];
$a = array("checkvalue1","checkvalue2", "checkvalue3", "checkvalue4", "checkvalue5","checkvalue6", "checkvalue7");
if (in_array($fieldvalue, $a)) {
return true;
}
else{
$invalid[] = RSFormProHelper::getComponentId("THEFIELDNAME");
}
Dropdown items from database
Items-text area on selectbox
The code below gets values from a Zoo-table in the database.
Remember to wrap the code with //< code >-tags:
$items = array();
$db = JFactory::getDbo();
$items[] = "|Vælg klinik[c]";
// Run the SQL query and store it in $results
$db->setQuery("SELECT id, name FROM #__zoo_item WHERE type = 'klinik' ");
$results = $db->loadObjectList();
// Now, we need to convert the results into a readable RSForm! Pro format.
foreach ($results as $result) {
$value = $result->id;
$label = $result->name;
$items[] = $value.'|'.$label;
}
// Multiple values are separated by new lines, so we need to do this now
$items = implode("\n", $items);
// Now we need to return the value to the field
return $items;
Get Zoo element value based on formfield value
PHP-Script $_POST
//GET EMAIL FROM ZOO ITEM - Klinik
$klinikid = $_POST['form']['klinik'][0];
// Define Zoo app instance
$app = App::getInstance('zoo');
// Zoo Record Id
$item = $app->table->item->get($klinikid);
$Element_Id = "46167f74-0781-4aab-b379-d6d63f213e85";
$element_value = $item->getElement($Element_Id)->getElementData()->get('value');
$_POST['form']['klinikmail'][0] = $element_value;
Get the textvalue from select box
Variable to use in E-mail or similar
Normally the field value is send in the email, but in some case i would rather send the text assosiated with the value.
In a selectbox my values are often ID's - and i would rather send the text-string.
Use: {FIELDNAME:value} to send the value
Use: {FIELDNAME:text} to send the textstring assosiated with thwe selected value
Get the URL of the last page visited before the form
Set as default value on hiddenfield
Remember to wrap with //< code >-tags
return $_SERVER['HTTP_REFERER'];
Comments (0)