Forums

Republish dynamic dropdowns?

customhost 25 May, 2010
Hi All,

I got a problem regarding the republishing of dynamically generated dropdowns and the ChronoForms content plugin.

I have created a ChronoForm where I have 15 dropdowns all containing the same values (numbers from 1-60). Due to I did not want to copy the code for these 60 equal options over and over again, I utilized Joomla's outstanding framework to do the job for me.

The code is as follows:


<?php
// function for generating the dropdowns 
function drawOptions($number=60) {
  $personen = array();  
  
  for($i=0; $i<=$number; $i++) {
    $personen[] = JHTML::_('select.option', $i, $i.' ');
  }
  
  return $personen;
}

// function to republish the values of the generic dropdowns
function republishValue($fieldname) {
  // dropdowns only contain numeric values so let's use the getInt() function to get the integers
  if(JRequest::getInt($fieldname, '', 'post')) return JRequest::getInt($fieldname, '', 'post');
  else return '0';
}

echo JHTML::_('select.genericlist', drawOptions(), 'adults', 'class="inputbox"', 'value', 'text', republishValue('adults')); 
?>


Please note that I could have used JHTML::_('select.integerlist') for the example instead of creating a "drawOptions()" function but the type of the dropdown doesn't matter in this case.

As you can see, I also created a custom republish function to republish the dynamic dropdowns.
The thing is that this function actually works as long as I call the form directly (using index.php?option=com_chronocontact&chronoformname=FORMNAME) but it doesn't when I include the form in an article using the ChronoForms content plugin (Syntax: {chronocontact}FORMNAME{/chronocontact}).

One thing I noticed during revealing this behavior is that when you call the form directly and print the $_POST values (using print_r($_POST);), this piece of code returns all the posted values. By using the content plugin, it simply returns an empty array. I think that these two things are connected two eachother as my custom republish function needs the $_POST values to correctly display the selected value.

Can anybody please help and maybe tell me how to republish dynamically generated dropdowns?
The ChronoForms republish function works exceptionally with static (= non-dynamic) dropdowns, btw ...

I'm using Joomla! 1.5.17 together with the ChronoForms component Version 3.1 RC5.2 and the ChronoForms plugin Version 3.1 RC5.2

Any help is greatly appreciated.

Thank you very much in advance!

Cheers,
Eric
nml375 25 May, 2010
Hi Eric,
Unfortunately, the plugin interacts differently with respect to republish. This is mainly due to the mechanism used to re-display the container article (using a 301 redirect). Thus, data is restored from the session storage instead.

ChronoForm does have a feature to provide a generic interface though, the $posted array. Instead of using JRequest::getXXx('somevar'), use $posted['somevar'], and things should work fairly well.

/Fredrik
customhost 26 May, 2010
Hi Fredrik,

thank you very much for your reply and for introducing the $posted array to me! :wink:

I changed the code according to your instructions and now it's all working fine:

<?php echo JHTML::_('select.genericlist', drawOptions(), 'adults', 'class="inputbox"', 'value', 'text', $posted['adults']); ?>


With this code, I even do not need my custom republishing function anymore.

Thank you very much once again for your help!

Cheers,
Eric
This topic is locked and no more replies can be posted.