• 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: fill form fields from joomla content and category

fill form fields from joomla content and category 5 years 9 months ago #38290

  • tanyat
  • tanyat's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Hello,
I have a form
name
position, phone, email, room (in one field of joomla content table (introtext)
department (as a category)

I need to change data for person - I use RS Forms to submit new data, for example I fill form field name, but all othe fields I want to be auomatically filled from jommla database (if person name in it). Is it possible to do this and if yes, how?
Thank you.
The administrator has disabled public write access.

fill form fields from joomla content and category 5 years 8 months ago #38323

  • tanyat
  • tanyat's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
More correct title is to autocomplete form fields on using dropdown.
I try to use this code
<?php
// This is where you would do any database call

if(!empty($_POST)) {
// Send back a jSON array via echo
echo json_encode(array("phone"=>'123-12313',"email"=>'test@test.com','position'=>'Medicine Hat','room'=>'556 19th Street NE'));
// Exit probably not required if you
// separate out your code into two pages
exit;
}
?>

<form id="tester">
<select name="client" id="client">
<option value="">-- Select Client Name -- </option>
<option value="1">John</option>
<option value="2">Smith</option>
</select>
<input name="phone" type="text" value="">
<input name="email" type="text" value="">
<input name="position" type="text" value="">
<textarea name="room"></textarea>
</form>



jQuery(document).ready(function($) {
// On change of the dropdown do the ajax
$("#client").change(function() {
$.ajax({
// Change the link to the file you are using
url: '/test.php',
type: 'post',
// This just sends the value of the dropdown
data: { client: $(this).val() },
success: function(response) {
// Parse the jSON that is returned
// Using conditions here would probably apply
// incase nothing is returned
var Vals = JSON.parse(response);
// These are the inputs that will populate
$("input[name='phone']").val(Vals.phone);
$("input[name='email']").val(Vals.email);
$("input[name='position']").val(Vals.position);
$("textarea[name='room']").val(Vals.room);
}
});
});
});
</script>

This works perfect.
I try to use it in RSFORMS. Create form with dropdown and fields as in code above.

Php code I put in Script called on form display section.
$action = JRequest::getWord('action');
if($action == 'ajax')
{


// This is where you would do any database call
if(!empty($_POST)) {
// Send back a jSON array via echo
echo json_encode(array("phone"=>'123-12313',"email"=>'test@test.com','room'=>'240','position'=>'researcher'));
// Exit probably not required if you
// separate out your code into two pages
exit;
}
}

jquery I put in to Javascript

<script>
jQuery(document).ready(function($) {
// On change of the dropdown do the ajax
$("#list").change(function() {
$.ajax({
// Change the link to the file you are using
url: '/index.php?option=com_rsform&formId=5&action=ajax',
type: 'post',
// This just sends the value of the dropdown
data: { list: $(this).val() },
success: function(response) {
// Parse the jSON that is returned
// Using conditions here would probably apply
// incase nothing is returned
var Vals = JSON.parse(response);
// These are the inputs that will populate
$("input[name='phone']").val(Vals.phone);
$("input[name='email']").val(Vals.email);
$("input[name='position']").val(Vals.position);
$("textarea[name='room']").val(Vals.room);

}
});
});
});
</script>

My dropdown has id "list".

and in rsforms this doesn't work at all...
Any help will be appreciated....
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!