• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: Passing values to another form

Passing values to another form 8 years 8 months ago #35636

  • robert.cole9
  • robert.cole9's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 1
Hello, I was wondering if it would be possible to pass the value from a drop down selection to another form so I can use its value to pull data from a database and auto populate fields based on the drop down value.

For example,

On my first form, I have a drop down field with the code
//<code>
 
$items = array();
// Prepare the database connection
$db = JFactory::getDbo();
// Keep this if you'd like a "Please select" option, otherwise comment or remove it
$items[] = "|Please Select[c]";
 
// Run the SQL query and store it in $results
$db->setQuery("SELECT PatID, fname, lname FROM rc_patientrec");
$results = $db->loadObjectList();
 
// Now, we need to convert the results into a readable RSForm! Pro format.
// The Items field will accept values in this format:
// value-to-be-stored|value-to-be-shown
// Eg. m|M-sized T-shirt
foreach ($results as $result) {
  $patid = $result->PatID;
  $fname = $result->fname;
  $lname = $result->lname;
  $items[] = $patid.'|'.$fname.' '.$lname;
}
 
$items = implode("\n", $items);
 
return $items;
 
//</code>

What I want to do next is send the value of a selection, in this case, the PatID, to another form and use it as a factor for my next query so the fields in the next form (I.e First Name, Last Name, Address, Phone, ect) would all be auto populated when the form loads with the info from that specific ID in the database table.

I understand that RSform has a return URL field so I can have the submit button go to a new form, but I would like to know how I can have the drop down value pass over to the next form so I can use it in a query.
The administrator has disabled public write access.

Passing values to another form 8 years 8 months ago #35651

  • adrianp
  • adrianp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 631
  • Thank you received: 146
Hello,

You can try similar steps (this relates on the RSForm!Pro specialized URL syntax for pre-filling field values):

- add a hidden field in your first form.

- use a script within "Scripts Called On Form Process" area to extract the desired database (which you would like to show in your second form) based on the dropdown selection.

- after extracting this data, craft the URL that should pre-fill your second form. Add this crafted URL within the hidden field's value.

- use the hidden field's placeholder within the Return URL property of your first form.

If everything is done correctly, the first form will redirect to your second one along with the URL parameters that will pre-fill your fields accordingly. If you want the form to immediately redirect after submit, disable the thank you message page.
This is not official customer support. To receive your support, submit a support ticket here.
The administrator has disabled public write access.

Passing values to another form 8 years 8 months ago #35658

  • robert.cole9
  • robert.cole9's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 1
Hello, thank you for the response. I believe I am on the right track, but I just need to know how to pull the data from the database.

In my Scripts Called on Form Process, I have this code
$db = JFactory::getDbo();
$db->setQuery("SELECT PatID, fname, lname, address FROM rc_patientrec WHERE PatID = $_POST["Patient"]");

(I also tried $_POST[Patient] and $_POST[form][Patient] and $_POST[form][Patient][0])

Inside my hiddenfield, I have
http://www.mysite.com/index.php?option=com_rsform&formId=11&form[First_Name]=fname&form[Last_Name]=lname&form[Address]=address

And for my Return URL, I have {Data:value}

This is the part where I believe I am wrong, since when I go to submit and go to the next form, the fields (Like First_Name) have the values I had in the URL instead of the value from the database. If possible, do you know what I'm supposed to put in the URL?


I also tried using this after selecting the data
$results = $db->loadObjectList();
 
  foreach ($results as $result) {
    $patient_firstname =  $result->fname; 
    $patient_lastname = $result->lname;
    $patient_address  = $result->address;
 }

In my URL, I replaced the values (fname, lname, ect) with $patient_firstname and so on, just to see if it would work that way, but the next form fields only show what I put in and not the value from the database.
Last Edit: 8 years 8 months ago by robert.cole9.
The administrator has disabled public write access.

Passing values to another form 8 years 8 months ago #35666

  • adrianp
  • adrianp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 631
  • Thank you received: 146
Hello,

Assuming the rest of query is specified correctly, the dropdown value can be included through a similar syntax:
$dropValue = $_POST['form']['Patient'][0];
$db = JFactory::getDbo();
$db->setQuery("SELECT PatID, fname, lname, address FROM rc_patientrec WHERE PatID ='".$dropValue."'");

Your hidden field should merely have the following in it's Default Value area:

www.mysite.com/index.php?option=com_rsform&formId=11

Finally, after extracting the desired database information, you can append the rest of the URL based on the returned values. For example (which can be further constructed for the other values you want to pass):
$_POST['form']['myHiddenFieldNameHere'] .= '&form[First_Name]='.$patient_firstname;

Depending on the fields of your second form you want to populate this URL syntax may differ (you should carefully follow how the URL parameters are specified in this article).
This is not official customer support. To receive your support, submit a support ticket here.
The administrator has disabled public write access.

Passing values to another form 8 years 8 months ago #35673

  • robert.cole9
  • robert.cole9's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 1
Hello, I appreciate you for helping me so much and showing me where to get started on this, but I'm still having issues with it.

I did do as you said and had my hidden field value just to link to the next form and nothing else

I placed the said code
$_POST['form']['myHiddenFieldNameHere'] .= '&form[First_Name]='.$patient_firstname;

in Script Called on Form Process after defining my variables, yet when I submit my form, the parameter string and variable is not being added onto the hidden field url value.

I tried doing some tests by just manually setting the PatID value and manually putting a random value after the = so it would fill in the next form field with what ever I put in, but it still did not work.
The administrator has disabled public write access.
The following user(s) said Thank You: Carnavalscomite

Passing values to another form 8 years 8 months ago #35675

  • robert.cole9
  • robert.cole9's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 1
I was able to get it to work. Here's what I did.

In my Scripts called on Form Process, I placed this
//********Load and select items from database based off of selected drop down value********
$dropValue = $_POST['form']['Patient'][0];
$db = JFactory::getDbo();
$db->setQuery("SELECT PatID, fname, lname, address FROM rc_patientrec WHERE PatID = $dropValue");
 
//********Get the results from the database and set them to variables********
$results = $db->loadObjectList();
 
foreach ($results as $result) {
    $patient_id = $result->PatID;
    $patient_firstname =  $result->fname; 
    $patient_lastname = $result->lname;
    $patient_address  = $result->address;
    }
 
//********Redirect form with the values retrieved from the database********
$mainframe->redirect('http://mysite.com/index.php?option=com_rsform&formId=11&form[PatID]='.$patient_id.'&form[First_Name]=' . $patient_firstname.'&form[Last_Name]='.$patient_lastname.'&form[Address]='.$patient_address);
 


Doing this, I was able to get the form to go to submit to the next form and auto fill in the fields with the info from the database.
The administrator has disabled public write access.

Passing values to another form 8 years 8 months ago #35679

  • robert.cole9
  • robert.cole9's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 1
Ok, I now have a new issue, but I believe it should be an easy fix, hopefully.

My issue is trying to insert two values selected on my patient info form and then when somebody selects the patient from the patient list form, I would like for it to send both values to my other form that I was working on.

Currently, I am only able to get one of the selections to show up. Inside of my database table, under the selection column, it shows the two selections I made in the same column, yet when I pull the data from the database and craft the URL, it only shows one of the selections and also breaks the rest of the URL. I had a radio group selection in my URL after the checkbox selection and the radio group did not show up unless I moved its url parameter to before the checkbox url parameter.

What I have for the selection URL is this
'&form[Selection][]='.$patient_selection

while my variable is set to this
$patient_selection = $result->Selection;

I am wondering how would I able to get both selections from the database column to fill in the form field? It works fine if there is only one selection, but having more than one selection breaks the url after filling in the first of the selections.

I have tried placing the $patient_selection into an items array and tried to implode it, but that did not work.
The administrator has disabled public write access.

Passing values to another form 8 years 8 months ago #35703

  • adrianp
  • adrianp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 631
  • Thank you received: 146
Hello,

If you've actually placed the following without replacing the hidden field name, it won't actually work:
$_POST['form']['myHiddenFieldNameHere'] .= '&form[First_Name]='.$patient_firstname;

Nevertheless, redirecting directly as you've done would basically work the same.

As for your latest reply, I'm not entirely sure I understand. You'll have to debug this by turn and see where exactly (either the syntax, value or URL syntax isn't specified correctly). The PHP code that you're using isn't processed by RSForm!Pro, in this case, this would be done by PHP itself.
This is not official customer support. To receive your support, submit a support ticket here.
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!