Forums

Double Drop Down

fasenderos 02 May, 2012
Hi to all,
I'm trying to create a double drop down with ChronoForms v4. I bought the Bob's manual (http://greyhead.net/how-to-docs/chronoforms-v4-using-ajax).

I copy/pasted all the example's code at the end of that book (obv changing the form's name), but when i select the state, instead of a list of countries appears the message "Powered By ChronoForms - ChronoEngine.com" 😲 😲

This is what I did:
1) Copy/Pasted the "Form HTML" code, inside the "HTML code" in the tab "Code" of the form
2) Copy/Pasted the "The Form JavaScript" code, inside the "Load JS" in the "On Load" event of the Advanced Widzard.
3) Created a new event with the name "ajax" and copy/pasted the "The Ajax event Custom Code" code inside a "Custom Code" element.
4)The only code I wrote is for mysql:

-- phpMyAdmin SQL Dump
-- version 3.1.3.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generato il: 18 ott, 2010 at 09:42 PM
-- Versione MySQL: 5.1.33
-- Versione PHP: 5.2.9

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `xxx`
--

-- --------------------------------------------------------

--
-- Struttura della tabella `jos_geopc_us`
--

CREATE TABLE IF NOT EXISTS `jos_geopc_us` (
  ID bigint(20) NOT NULL,
  ISO2 varchar(6) NOT NULL,
  Region1 varchar(60) NOT NULL,
  Region2 varchar(60) NOT NULL
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dump dei dati per la tabella `jos_geopc_us`
--

INSERT INTO `jos_geopc_us` (`id`, `ISO2`, `Region1`, `Region2`) VALUES
(1, 'IT-PI', 'Piemonte', 'Torino'),
(2, 'IT-PI', 'Piemonte', 'Alessandria'),
(3, 'IT-PI', 'Piemonte', 'Asti'),
(4, 'IT-LO', 'Lombardia', 'Milano'),
(5, 'IT-LO', 'Lombardia', 'Bergamo'),
(6, 'IT-LO', 'Lombardia', 'Como');


I don't know if I can post the rest of the code, cause it's completely taken from that manual, so I need the permission of the author.
Thanks in Advance

P.S.:
Chronoforms V. 4.0 RC3.11
Joomla! V. 2.5.4
GreyHead 02 May, 2012
Hi fasenderos ,

Please post a link to the form so I can take a quick look. It sounds as though nothing is being returned from the Ajax call.

You probably need to add a Show STopper action to the ajax action to prevent the strap-line from displaying.

Bob
fasenderos 02 May, 2012
Hi Bob,

here's the link

Thanks
Andrea

*edit: I have added a Show STopper action to the ajax action. Now when you select the state, in the county field appears "searching..." for 2 seconds, and then nothing
GreyHead 05 May, 2012
Hi Andrea,

Checking with FireBug shows that what is being returned is the ChronoForms strap-line (adding the Show Stopper should have blocked this) and a 500 Internal Server error. So I suspect that there is a problem with the code in the Ajax event.

Please re-copy and paste the Ajax code here so I can see if anything has got lost in the the various moves.

Bob
fasenderos 07 May, 2012
Hi Bob,

here's the Ajax code
<?php
$state_id =& JRequest::getString('sid', '', 'post');
if ( $state_id ) {
$db =& JFactory::getDBO();
$query = "
SELECT DISTINCT `Region2` AS `id`, `Region2`
FROM `#__geopc_us`
WHERE `ISO2` = '$state_id'
ORDER BY `Region2`;
";
$db->setQuery($query);
$data = $db->loadObjectList();
if ( count($data) ) {
$m = new stdClass();
$m->id = 0;
$m->Region2 = '==?==';
$data = array_merge(array($m), $data);
$return = JHTML::_('select.genericlist', $data, 'Region2',
'class="inputbox required select" size="1" ', 'id', 'Region2',
} else {
$return = "Sorry, we couldn't find that state";
}
} else {
$return = "Sorry, we couldn't find a state id";;
}
echo $return;
// stop any further processing
$mainframe->close();
?>


Andrea
Max_admin 07 May, 2012
Hi Andrea,

Please try to include this line before the last one:

$mainframe =& JFactory::getApplication();


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
fasenderos 08 May, 2012

Hi Andrea,

Please try to include this line before the last one:

$mainframe =& JFactory::getApplication();


Regards,
Max


Hi Max,
I added that code, but didn't works.
Regards
Andrea
Max_admin 09 May, 2012
Hi,

Try to access the AJAX event using your browser directly, make sure it works and gives the correct results without any errors.

example: index.php?option=com_chronoforms&chronoform=my_form&event=XXXXXX
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
fasenderos 10 May, 2012
Hi Max,
sorry but I'm not a wizard, so i don't know if there are any errors..the form's name is "prova" and the Ajax event name is "ajax"...this is the link, can you check it for me?

Thanks,
Andrea
Max_admin 10 May, 2012
I'm getting a full page load there, so its not working correctly, what's the code you have there now ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
fasenderos 10 May, 2012
In the "On ajax" event i have a Show Stopper action and a Custom Code action with that ajax code
<?php
$state_id =& JRequest::getString('sid', '', 'post');
if ( $state_id ) {
$db =& JFactory::getDBO();
$query = "
SELECT DISTINCT `Region2` AS `id`, `Region2`
FROM `jos_geopc_us`
WHERE `ISO2` = '$state_id'
ORDER BY `Region2`;
";
$db->setQuery($query);
$data = $db->loadObjectList();
if ( count($data) ) {
$m = new stdClass();
$m->id = 0;
$m->Region2 = '==?==';
$data = array_merge(array($m), $data);
$return = JHTML::_('select.genericlist', $data, 'Region2',
'class="inputbox required select" size="1" ', 'id', 'Region2',
} else {
$return = "Sorry, we couldn't find that state";
}
} else {
$return = "Sorry, we couldn't find a state id";;
}
echo $return;
// stop any further processing
$mainframe =& JFactory::getApplication(); <-- Added after your suggestion
$mainframe->close();
?>


Regards
GreyHead 15 May, 2012
Hi fasnaderos,

I think that this link
http://www.onlinecontabilita.it/index.php?option=com_chronoforms&chronoform=prova&event=ajax
needs to be
http://www.onlinecontabilita.it/index.php?option=com_chronoforms&chronoform=prova&event=ajax&tmpl=component
otherwise the template will be included in the returned result and you get the 'full page' that Max described.

Bob
matteo4481 07 Sep, 2012
Hi,
I have the same configuration, but with this error when repositioned to select's value to 0:

Object #<HTMLSpanElement> has no method 'setHTML'

Thank!
Matteo
Max_admin 08 Sep, 2012
Hi Matteo,

I have to test this, please post a link here or send it through the contact us page.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
matteo4481 08 Sep, 2012
this is the link to my test form. This is a triple but i have tested with double and i have the same result.
Triple

Double

Thank!
Matteo
GreyHead 27 Sep, 2012
HI Matteo,

I suggest that you try replacing this line
$m->id = 0;
with
$m->id = '';
This will give the ==??== option an empty value instead of 0 which seems to be causing the problem.

Bob
Davila 11 Dec, 2012
Hi Bob.
I have a similar problem, and I tried several things and it seems that the problem is not being called the event containing the ajax, allways recibe the same message in the drop-down:loading Failed.
I load my data in a custom php in a event called ajax, i add the custom code.
Thanks in advance!!
GreyHead 12 Dec, 2012
Hi Davila,

Please post a link to the form so I can take a quick look.

Bob
GreyHead 15 Dec, 2012
Hi Davila,

Checking in my Browser Web Developer tools I see a 500 Internal Server error and a System Message about Ajax. If I call the Ajax URL directly I just see the ChronoForms strapline which makes me wonder if the call is to the right event. Please take a Form Backup using the icon in the Forms Manager and post it here (as a zipped file) or PM or email it to me and I'll take a closer look.

Bob
This topic is locked and no more replies can be posted.