Display information submitted in a different form
In this article we will demonstrate how to easily display information submitted in a different form on your current form page using the submission's id. This id is a unique number that is automatically generated for each form submission.
Step 1: Create a hidden field in your first form
The first thing you need to do is to create a hidden field(named exactly "hash" for this example) in your form that will store a unique sequence and will be used in order to securely identify each submission from the first form.
For generating the unique sequence, a script as the following must be added in the Default Value section of the hidden field:
//<code> return md5(uniqid(microtime() . $_SERVER['REMOTE_ADDR'])); //</code>
Using this hash parameter, you can stop the user from changing the URL parameters and see other form submissions.
Step 2: Point to the second form
The second thing you need to do is create a link in your first form that will point to the second form. This link will need to contain an additional parameter that will contain the unique sequence generated in the hidden field(more information regarding sending and capturing parameters from the url can be found here), for example:
http://www.your-site-name.com/index.php?option=com_rsform&formId=your-second-form-id&hash={hash:value}
Step 3: Identify the fields that needs to be displayed
After this you will need to identify the fields that you want to use. Next you will need to go to Components > RSForm!Pro > Manage forms, select your second form, go to the Form layout tab and add the field placeholders of the fields you want to display in the code found on this tab, for example:
<fieldset class="formFieldset"> <legend>{global:formtitle}</legend> {error} <p>Data submitted in a different form:</p> <p>FullName field : {FullName:value}</p> <p>Email field : {Email:value}</p> <p>Age field : {Age:value}</p>
The {Fullname:value}, {Email:value} and {Age:value} placeholders are the actual field placeholders of the fields you want to display the information for from your other form.
Step 4: Add a PHP script that replaces the placeholders with values
After you add all the placeholders you want in the code from the Form layout tab, you will need to go to Components > RSForm!Pro > Manage forms, select your second form, go to the PHP Scripts tab and add the following code in the Scripts called on form display field:
// Get the hash from the URL if ($hash = Joomla\CMS\Factory::getApplication()->input->getCmd('hash')) { $db = Joomla\CMS\Factory::getDbo(); $db->setQuery("SELECT SubmissionId FROM #__rsform_submission_values WHERE FieldValue = " . $db->q($hash) . " AND FieldName='hash'"); $submissionId = $db->loadResult(); if ($submissionId) { // Use the RSForm! Pro helper to retrieve the replacements. list($replace, $with) = RSFormProHelper::getReplacements($submissionId); // Replace the placeholders. $formLayout = str_replace($replace, $with, $formLayout); } }
Set a default value in a radio / checkbox group
Another possible scenario that can be implemented in a similar manner is rendering a checkbox / radio group item in the second form as the default selection, based on the parameter transmitted in the first form. To achieve this, please add the following code in the radio / checkbox group field's Items area:
//<code> // Specify the radio/checkbox group's items, they will be compared with the passed parameter. $items = array('Item 1', 'Item 2', 'Item 3'); // Grab the parameter from the URL. // The following works if the URL looks like index.php?option=com_rsform&formId=2&myparameter=some_value $value = Joomla\CMS\Factory::getApplication()->input->getString('myparameter'); // The following converts $value to an array, so that we can check multiple items // if this is desired. $value = (array) $value; // Loop through all of the defined items. foreach ($items as $i => $item) { // Checks if the current item is in our $value array. if (in_array($item, $value)) { // Use [c] to select it. $items[$i] .= '[c]'; } } // Return the list of items, separated by a new line. return trim(implode("\n", $items)); //</code>
The code provided above is no longer necessary, as we have introduced this functionality as a default feature. The How do I pass a parameter through the URL and how can I catch it article in our documentation explains how it's done.
21 persons found this article helpful.