• 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: Setting default values based on a textbox value

Setting default values based on a textbox value 9 years 4 weeks ago #34709

  • mark63
  • mark63's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 11
Hi,
I have a dynamic dropdown on form A to pass an ID to form B via the return URL
I have created a text field to pass the id value into and called it DogsID which appears to work fine and displays the expected value.
I now wish to populate a few other fields in form B based on this id.

In the KC_Name fields default value I have inserted this code.

//<code>
$db = JFactory::getDbo();
$db->setQuery("SELECT `KC_Name` FROM `#__dogs_details` WHERE `Dogs_id`='1' ");
return $db->loadResult();
//</code>

This returns the expected value.

How do I replace the "1" with the value passed by the url into the DogsID field
Cheers
Mark
Last Edit: 9 years 4 weeks ago by mark63.
The administrator has disabled public write access.

Setting default values based on a textbox value 9 years 20 hours ago #34955

  • estarren
  • estarren's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
I have the same question is it possible to post the solution?
Thanks in advance.
The administrator has disabled public write access.

Setting default values based on a textbox value 8 years 11 months ago #35049

  • mark63
  • mark63's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 11
Hi,
I am no expert but this how I managed to get this to work.

Form A
Dropdown called DogChoice
Default value:
//<code>
// Prepare the empty array
$items = array();
// Prepare the database connection
$user = JFactory::getUser();
$db = JFactory::getDbo();
$userId = $user->get('id');
// Keep this if you'd like a "Please select" option, otherwise comment or remove it
$items[] = "|Please Select[c]";

// Is the user logged in?
if ($userId) {
// Grab the value from the database.
$db->setQuery("SELECT * FROM `#__dogs_details` WHERE `user_id`='".$userId."'");
$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) {
$value = $result->Dogs_id;
$label = $result->KC_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;
//</code>

Return url: http: yoursite.com/index.php?option=com_rsform...ter={DogChoice:value}


Form B

Textbox called myparameter
Default value:
//<code>
if (JRequest::getVar('myparameter') != '')
{
$myparameter_value = JRequest::getVar('myparameter');
return $myparameter_value;
}
else
{
return 'No value';
}
//</code>

Textbox for KC_Name
default value:

//<code>
$myparameter_value = JRequest::getVar('myparameter');

$db = JFactory::getDbo();
$db->setQuery("SELECT `KC_Name` FROM `#__dogs_details` WHERE `Dogs_id`=' $myparameter_value' ");
return $db->loadResult();
//</code>

Hopefully this will set you on the right path.
Cheers
Mark
Last Edit: 8 years 11 months ago by mark63.
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!