Hi, Bob et all. Here again! 😢 I added the line and tested the code and nothing happens.
Now, I have discarded a couple things as the source of error: (1) The original email checking code was working OK so the CF actions setup and code locations are fine. (2) I have tested the php part manually defining $patroc_id and it worked fine, so the problem is either in the first line of php which receives the contents for $patroc_id or the js code.
Could you take a look and see if you can spot what I missed?
Just to clarify, the two inputs involved are tagged id="patroc_id" and id="patroc_nombre". What it should do is that when you input the patroc_id, patroc_nombre should be automatically populated with the corresponding name from the database. Here's the code again:
<script type="text/javascript">
window.addEvent('domready', function() {
// set the url to send the request to
var url =
'index.php?option=com_chronoforms&chronoform=form_inscripcion&event=ajax&format=raw';
var patroc_id = $('patroc_id');
patroc_id.addEvent('blur', function() {
// check that the email address is valid
regex = [0-9]+;
var value = patroc_id.value.trim();
if ( value.length >= 6 && regex.test(value) ) {
// if all is well send the JSON request
var request = new Request({
method: 'post',
url: url,
data: { 'patroc_id' : patroc_id },
onComplete: function(r) {
// Populate patroc_nombre with $response
$('patroc_nombre').value = result;
}
}).send();
}
});
});
</script>
<?php
// Get the query info
$patroc_id = JRequest::getString('patroc_id', '', 'post');
$patroc_id = trim($patroc_id);
$patroc_id = ltrim($patroc_id,"0");
if ( $patroc_id ) {
// Retrieve sponsor's name from database
$db =& JFactory::getDBO();
$query = "
SELECT apellidos, nombres
FROM `#__data_usuarios`
WHERE `usu_id` = ".$patroc_id.";";
$db->setQuery($query);
$result = $db->loadAssoc();
if ( $result ) {
$response = $result['nombres'].' '.$result['apellidos'];
}
else {
$response = '-- El código no existe --';
}
}
//Send the reply
echo $response;
?>
Thanks a lot.
David