|
Captain Paralytic
|
 |
« on: March 10, 2007, 10:52:45 pm » |
|
Here is a small package that uses simple AJAX to invoke logic in the before forms piece to update a field on the form.
It may be used when server side validation is required, but the form's contents needs to be preserved.
|
|
|
« Last Edit: March 11, 2007, 01:42:34 pm by Captain Paralytic »
|
Logged
|
|
|
|
|
Bitsqueezer
|
 |
« Reply #1 on: June 07, 2007, 03:12:07 am » |
|
Hi,
thanx for this demo, I adapted it so now you can use the querylist to search for data in a database-table.
In the demo I used the standard Joomla user table so if you want to test it just type in a username (the login name) of your Joomla in the inputfield and click "search".
The other button shows how to fill in the querylist with static text instead of searching in the database.
It's not perfect, I know, but I think it shows the "how-to".
Cheers,
Christian
|
|
|
|
Logged
|
|
|
|
|
j_pablo_gn
|
 |
« Reply #2 on: December 08, 2008, 09:18:38 pm » |
|
Hi,
In my PC your packages are not working, I did a mix of both of them but it does not work... I attach it, may be you can have a look.
Thanks. J. Pablo.
PLEASE, BE CAREFUL, DON'T COPY THIS PACKAGE, IT IS A TEST AND IT IS NOT WORKING!!
|
|
|
|
Logged
|
|
|
|
|
Captain Paralytic
|
 |
« Reply #3 on: December 08, 2008, 09:50:12 pm » |
|
Try this version
|
|
|
|
Logged
|
|
|
|
|
j_pablo_gn
|
 |
« Reply #4 on: December 10, 2008, 06:58:54 am » |
|
Hi,
Thanks a lot Captain.
I check your package ant works fine, and I did the same modification (and some others) over mine, and it's also working.
I have seen that the difference is:
echo ' <script language="javascript" type="text/javascript"> var url = "'.ff_makeSelfUrl('&ff_param_aj=').'"; // The server-side script url = "{mossite}/index2.php?option=com_facileforms&ff_name='.$this->formrow->name.'&ff_param_aj="; </script> ';
Two questions: 1. Could you tell me why it works for you but in my case I need this extra line? 2. How can I do this but for two or more parameters? I mean, I just have the parameter 'ff_param_aj', so I neen to send for example the family name to look for data in the db, and right after that the country. Do I need to add in lines below something like "escape('country_'+id_pais) or escape('familyname_'+familyname)"?
JS Send: http.open("GET", url + escape(id_pais), true);
PHP Receive: $aj = ff_getParam('ff_param_aj'); if ($aj) {...}
Thanks a lot, I like quite a lot how AJAX works it is something I was missing in this kind of development, and thanks to you and Christian I can start using it. J. Pablo.
|
|
|
|
|
Logged
|
|
|
|
|
j_pablo_gn
|
 |
« Reply #5 on: December 10, 2008, 07:05:21 am » |
|
I also test the original component, by taking out the iFrame, and it also works.
I would like to know what's the diference, what can I read to have a better understanding of this?
Many thanks. J. Pablo.
|
|
|
|
|
Logged
|
|
|
|
|
j_pablo_gn
|
 |
« Reply #6 on: December 22, 2008, 07:18:40 pm » |
|
There all,
Here is a mix of Christian & Captain examples, for me this one is much more simple that the other two, so may be it can help someone.
Cheers (and thanks to both of you). J. Pablo.
|
|
|
|
Logged
|
|
|
|
|
j_pablo_gn
|
 |
« Reply #7 on: December 22, 2008, 11:29:57 pm » |
|
One thing,
It is not the same when I send my data through a global variable, than when I send them by ussign 'echo'.
The first one, is working fine. <?php global $lista; return $lista; ?> But the second one no. echo '0;$record->id;$record->name\n';
The second one, transform especial characters in other characters. For example 'ñ' -> '^;'
Is there any other way do this without ussing 'echo'?.
Many thanks. J. Pablo.
|
|
|
|
|
Logged
|
|
|
|
|
Captain Paralytic
|
 |
« Reply #8 on: December 22, 2008, 11:52:09 pm » |
|
One thing,
It is not the same when I send my data through a global variable, than when I send them by ussign 'echo'.
The first one, is working fine. <?php global $lista; return $lista; ?> But the second one no. echo '0;$record->id;$record->name\n';
The second one, transform especial characters in other characters. For example 'ñ' -> '^;'
Is there any other way do this without ussing 'echo'?.
Many thanks. J. Pablo.
What you have said does not make sense!!! You said that the first one works, but the second one using echo does not. Then you ask if there is a way to do this not using echo. Well surely the answer is the first way. You have answered your own question! Also I do not see how echo '0;$record->id;$record->name\n'; would achieve anything since it is in single quotes and thus will not be parsed.
|
|
|
|
|
Logged
|
|
|
|
|
j_pablo_gn
|
 |
« Reply #9 on: December 23, 2008, 11:02:47 am » |
|
You are right, this is the code:
// ------ COMUNIDADES DE UN PAIS ------------ $pais = ff_getParam('ff_param_pais');
if ($pais) { $strquery = "SELECT name_sp, id_region FROM #__ns_data_geo_region WHERE id_country = '$pais' "; $encontrados = ff_select( $strquery ); while (@ob_end_clean());
if (count($encontrados) > 0){ // lines of the table foreach ($encontrados as $reg) { echo "0;$reg->name_sp;$reg->id_region\n"; } } echo "0;Otro;-1\n"; exit; }
May be I can write the same, to put everything in $str_data, and after call it from javascript.... I am goint to try.
Thanks and sorry. J. Pablo.
|
|
|
|
|
Logged
|
|
|
|
|
j_pablo_gn
|
 |
« Reply #10 on: December 23, 2008, 10:50:25 pm » |
|
Hello Captain,
If I send the data with 'echo' or 'print' I don't receive special characters (atleast not the good ones). But this is not a problem with the db, because if I write "<?php global $lista_provincia; return $lista_provincia; ?>" in the option section of a selectlist, I receive everything perfectly.
So, I tested this lines below to see what happens, but it doesn't work (I imagine that I am missunderstanding something).
//-------------------------------------------------------------------------- // PHP side //-------------------------------------------------------------------------- $lista_provincia.="0;Provincia;0\n";
$pais = ff_getParam('ff_param_pais');
if ($pais) { $strquery = "SELECT name_sp, id_region FROM #__ns_data_geo_region WHERE id_country = '$pais' "; $encontrados = ff_select( $strquery ); while (@ob_end_clean());
$lista_provincia = ""; if (count($encontrados) > 0){ // lines of the table foreach ($encontrados as $reg) { $lista_provincia.="0;$reg->name_sp;$reg->id_region\n"; } } $lista_provincia.="0;Otro;-1\n"; // echo $lista_provincia; // don't send anything, keep it in $lista_provincia // print $lista_provincia; exit; }
//-------------------------------------------------------------------------- // JavaScript side //--------------------------------------------------------------------------
function updateProvincia() { var pais_selec = ff_getElementByName("slPais"); var id_pais = pais_selec.options[pais_selec.selectedIndex].value; //alert(url_pais + escape(id_pais)); http.open("GET", url_pais + escape(id_pais), true); http.onreadystatechange = handleHttpResponseProvincia; http.send(null); }
function handleHttpResponseProvincia() {
var selectlist = ff_getElementByName('slComunidad'); var elementos; var datos;
if (http.readyState == 4) {
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // !! it doesn't do anything, it takes old $lista_provincia value // !! this is "0;Provincia;0\n" // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! var results = "<?php global $lista_provincia; return $lista_provincia; ?>";
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! alert(results); // !! shows the old varible value, this is: "0;Provincia;0\n" !! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//results = http.responseText; // should be empty, because I cancel echo function
// limpia el select list while (selectlist.length>1){ selectlist.remove(selectlist.length-1); }
// si el resultado es positivo, metelo en la lista if (results.length > 0) { var matriz = results.split('\n'); for(var i=0; i< matriz.length-1; i++) { // parte cada elemento de la matriz en sus partes datos = matriz; elementos = datos.split(';'); // crea el option y rellenalo var a = document.createElement('option'); a.text = elementos[1]; a.value = elementos[2];
// añadelo al select list try { selectlist.add(a, null); // standards compliant; doesn't work in IE } catch(ex) { selectlist.add(a); // IE only } } } } }
¿Could you tell me what I am doing wrong?. I can send 'á' with echo, but why do I receive other thing?.
Many thanks. J. Pablo.
|
|
|
|
|
Logged
|
|
|
|
|
Captain Paralytic
|
 |
« Reply #11 on: December 23, 2008, 11:50:45 pm » |
|
I tested this lines below to see what happens, but it doesn't work It doesn't work tells me nothing. Please say what actually happens and also what you are trying to achieve
|
|
|
|
|
Logged
|
|
|
|
|
j_pablo_gn
|
 |
« Reply #12 on: December 24, 2008, 10:16:23 am » |
|
Good morning.
In my DB, I have this: 'Álava'.
1. If a send it to the client side through a global PHP variable <?php global $a; return $a; ?>, it arrives well.
2. If a send it like an 'echo' or 'print', it arrives like '?lav', which is not right.
3. I try to mix both solution, this: a. Do a request to the server. b. In the server update the variable after checking the DB (original value is 'Provincia'). c. Get the varialbe updated through <?php....?> in the handleHTTPResponse(). This is not working, because I receive the previous value of the variable (this is 'Provincia' instead of 'Álava').
¿Is there any way to send special characters through 'echo' without lossing them?, if not, ¿is there any other way to do this?.
Many thanks. J. Pablo.
|
|
|
|
|
Logged
|
|
|
|
|
j_pablo_gn
|
 |
« Reply #13 on: December 28, 2008, 09:46:50 pm » |
|
Good night,
Other thing I have detected is that it is not working in the same way when I am logged in and when not (I send a picture).
I imagine that it is something related with my form... but I don't know jet.
Merry Christmas. J. Pablo.
|
|
|
|
Logged
|
|
|
|
|