I have used this code to save the RSForm data in a cookie and if the user tries to fill in the same form again, the previously entered data is loaded as default values:
Script called on form display:
// COOKIES
$inputCookie = JFactory::getApplication()->input->cookie;
$bdayd = $inputCookie->get('rsformdatabdayd', '', 'string');
$bdaym = $inputCookie->get('rsformdatabdaym', '', 'string');
$bdayy = $inputCookie->get('rsformdatabdayy', '', 'string');
echo '<script>
document.getElementById("bdayd").value = "'. $bdayd .'";
document.getElementById("bdaym").value = "'. $bdaym .'";
document.getElementById("bdayy").value = "'. $bdayy .'";
</script>';
Script called on form process:
// COOKIES
$inputCookie = JFactory::getApplication()->input->cookie;
$inputCookie->set('rsformdata', $_POST['form']);
$inputCookie->set('rsformdatacountry', $_POST['form']['country']);
$inputCookie->set('rsformdataaddress-level1', $_POST['form']['address-level1']);
$inputCookie->set('rsformdatastudies', $_POST['form']['studies']);
$inputCookie->set('rsformdataemployment', $_POST['form']['employment']);
$inputCookie->set('rsformdataage', $_POST['form']['age']);
$inputCookie->set('rsformdatabdayd', $_POST['form']['bday']['d']);
$inputCookie->set('rsformdatabdaym', $_POST['form']['bday']['m']);
$inputCookie->set('rsformdatabdayy', $_POST['form']['bday']['y']);
$inputCookie->set('rsformdatasuscribe', $_POST['form']['suscribe']);
In the fields, I have these values (I'll only post two as example):
Textbox "name" Default Value:
//<code>
$inputCookie = JFactory::getApplication()->input->cookie;
$value = $inputCookie->get('rsformdata', '', 'array');
return $value['name'];
//</code>
Dropdown "country" Default value:
//<code>
$options = array('|País de residencia:',
'ES|España',
'MX|México',
'CO|Colombia',
'ZM|Zambia',
'ZW|Zimbabue');
$inputCookie = JFactory::getApplication()->input->cookie;
$value = $inputCookie->get('rsformdatacountry', '', 'array');
$items = "";
foreach ($options as $options_item) {
$items .= $options_item;
$active = explode('|', $options_item);
if (in_array($active[0], $value)) {
$items .= "[c]\n";
} else {
$items .= "\n";
}
}
return trim($items);
//</code>
The code successfully updates the form fields with the preserved values. If someone has already filled in the form, the values are loaded, but I get these php warnings and notices:
[28-Aug-2019 17:08:31 Europe/Berlin] PHP Warning: Illegal string offset 'address-level2' in /home/aacom/public_html/test/administrator/components/com_rsform/helpers/field.php(67) : eval()'d code on line 4 [28-Aug-2019 17:08:31 Europe/Berlin] PHP Notice: Uninitialized string offset: 0 in /home/aacom/public_html/test/administrator/components/com_rsform/helpers/field.php(67) : eval()'d code on line 4 [28-Aug-2019 17:08:31 Europe/Berlin] PHP Warning: Illegal string offset 'street-address' in /home/aacom/public_html/test/administrator/components/com_rsform/helpers/field.php(67) : eval()'d code on line 4 [28-Aug-2019 17:08:31 Europe/Berlin] PHP Notice: Uninitialized string offset: 0 in /home/aacom/public_html/test/administrator/components/com_rsform/helpers/field.php(67) : eval()'d code on line 4 [28-Aug-2019 17:08:31 Europe/Berlin] PHP Warning: Illegal string offset 'postal-code' in /home/aacom/public_html/test/administrator/components/com_rsform/helpers/field.php(67) : eval()'d code on line 4 [28-Aug-2019 17:08:31 Europe/Berlin] PHP Notice: Uninitialized string offset: 0 in /home/aacom/public_html/test/administrator/components/com_rsform/helpers/field.php(67) : eval()'d code on line 4 [28-Aug-2019 17:08:31 Europe/Berlin] PHP Warning: in_array() expects parameter 2 to be array, string given in /home/aacom/public_html/test/administrator/components/com_rsform/helpers/field.php(67) : eval()'d code on line 24 [28-Aug-2019 17:08:31 Europe/Berlin] PHP Warning: in_array() expects parameter 2 to be array, string given in /home/aacom/public_html/test/administrator/components/com_rsform/helpers/field.php(67) : eval()'d code on line 24 [28-Aug-2019 17:08:31 Europe/Berlin] PHP Warning: in_array() expects parameter 2 to be array, string given in /home/aacom/public_html/test/administrator/components/com_rsform/helpers/field.php(67) : eval()'d code on line 24 [28-Aug-2019 17:08:31 Europe/Berlin] PHP Warning: in_array() expects parameter 2 to be array, string given in /home/aacom/public_html/test/administrator/components/com_rsform/helpers/field.php(67) : eval()'d code on line 24 [28-Aug-2019 17:08:31 Europe/Berlin] PHP Warning: in_array() expects parameter 2 to be array, string given in /home/aacom/public_html/test/administrator/components/com_rsform/helpers/field.php(67) : eval()'d code on line 24 [28-Aug-2019 17:08:31 Europe/Berlin] PHP Warning: in_array() expects parameter 2 to be array, string given in /home/aacom/public_html/test/administrator/components/com_rsform/helpers/field.php(67) : eval()'d code on line 99 [28-Aug-2019 17:08:31 Europe/Berlin] PHP Warning: in_array() expects parameter 2 to be array, string given in /home/aacom/public_html/test/administrator/components/com_rsform/helpers/field.php(67) : eval()'d code on line 99 [28-Aug-2019 17:08:31 Europe/Berlin] PHP Warning: in_array() expects parameter 2 to be array, string given in /home/aacom/public_html/test/administrator/components/com_rsform/helpers/field.php(67) : eval()'d code on line 13 [28-Aug-2019 17:08:31 Europe/Berlin] PHP Warning: in_array() expects parameter 2 to be array, string given in /home/aacom/public_html/test/administrator/components/com_rsform/helpers/field.php(67) : eval()'d code on line 13
Any idea how to avoid these notices and warnings?