I am have built a radio button in Chronoform by reading data from MySQL. The radio button consists of statements such as:
o Education for Peace - Intake 2009 (Date: 2008-12-19)
The buttons are printed in the form without any problem. However, only the first word in the chosen button (for example Education” is passed to the atabase linked to the form or the email generated by it. I can not figure out what the problem is? I apprecite any help as I am stuck.
Thanks
Fred
Hi fred14,
Please can you post the HTML for the button. The most likely explanation is that ChronoForms fails to remove all the spaces in the button name or doesn't apply a value to it.
Bob
Bob,
The code you have suggested works perfectly. I can now continue with the rest of the work.
Thank you for your help.
Fred
Bob,
After further testing of the code, I have noticed that if there is ' in the chosen radio button, the value is truncated at that point. For example if the chosen button is:
YBCL program in Baha'i studies- (Date: 27/1/09)
only (YBCL program in Baha) is passed as value.
Is there anyway to avoid this problem?
Thanks
Fred
Bob,
Your suggested code is working perfectly now and the form has gone live.
Many thanks
Fred
Hi Fred,
I have edited your code alittle:
<?php
$db = & JFactory::getDBO();
$query = "SELECT dates, title, alias, published FROM . . . WHERE published LIKE 1";
$db->setQuery($query);
$rows = $db->loadAssocList();
foreach ( $rows as $row )
{
$ivalue=$row['title'] . ", " . $row['dates'] . ", " . $row['alias'];
$value = htmlspecialchars($ivalue, ENT_QUOTES);
$checked = "";
if($_POST['course_date'] == $value){$checked = "checked";}
echo "<input name='course_date' type='radio' ".$checked." value='$value' />
<span style='color:#006600;'>{$row['title']} (Date: {$row['dates']})</span><br />";
}
?>
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Thank you for the suggested code. I have tried it. Something strange happens. Initially the right radio button is checked. But within a second, the checked button is unchecked. I think the code still does not remember which one was checked and build the radio button from scratch.
Fred
Bob,
I have printed different values and also $checked. The code seems to be doing its job. The $checked is set to checked for the button ticked by the client. But somehow this value is lost when the form regeneration is complete as after re- submit $_POST['course_date'] is blank. I have spent hours today exploring all aspects of the course. Does ChronoForm reset the form values after anti-spam check? I am not getting far.
Fred
I have done further work on the code. I am now convinced that the $_POST is reset after the form is republished. What I have done is replace the Submit class button with an HTML submit button. After republishing, I print the value of of $_POST['course_date'] after submit. It has the right value and the right radio is checked. However, after a second it is unchecked. I don't know where to go from here.
Fred
Now I have chosen the option of not to republish for the anti-spam. This time radio button data is returned and others were lost. Is $_POST reset after republishing? That is the only possibility.
Fred
Hi Fred,
I've no real idea what is happening here, nor do I have time to dig into it at the moment.
$_POST isn't usually set on resposting and I can't think why your selection should suddenly change unles there is some sneaky JavaScript doing somethign odd in the background.
ChronoForms usually uses a showform() function to re-display the page and showform($_POST) will show it with the $_POST values and plain showform() show it without. I don't know if this helps at all.
Bob
Hi Fred,
put Bob's code below at the top of the form HTML between 2 PHP tags and show me whats the output once the form has been loaded with a wrong captcha assuming you will make a radio choice of course!
print_r($_POST); echo "<br /><br />";
echo "value: ".print_r($value, true)."<br /><br />";
Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Hi max,
This is the print out:
Array ( [course_date] => Women\'s Retreat, 2009-02-20, 95 [first_name] => Fred [last_name] => [date_birth] => [address] => [town] => [state] => NSW [postcode] => [phone] => [mobile] => [email] => [request] => [chrono_verification] => [1978cb08648a9539214cca2e313be3d7] => 1 [cf_wrong_security_code] => 1 )
The array([course_date] shows the right radio button checked but it is not shown on the screen after reloading of the form. The other fields were left blank apart from first_name.
Thank you for help.
Fred
Hi Fred,
It may be that something in that value string causes problems - ',', '\', and '-' can all cause parsing problems unless they are very carefully handled. I'd use a simplified version like wr_20090220_95
Bob
Hi Fred,
what if you disabled the "republishing" ? do the radios load the selected value ?
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Hi Max,
Yes - when I disabled the "republishing", the radios select the right value. But other fields are lost.
Fred
Hi Fred,
That's good! I think this is some conflict between the JS used to load the radios and the dynamic creation of the radios using the PHP, so your only option now is to load all the fields using the old way with PHP, there is some FAQ about this, you just need to echo the $_POST value of every field in your field's value attribute!
Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.