but the problem is... if i select multiple answer, only the last answer record at the table.
please help.
thanks.
[file name=check.txt size=1147]http://www.chronoengine.com/components/com_fireboard/uploaded/files/check.txt[/file]

you meant i have to name all the check box music[]?
<?php
if ( is_array($_POST[field_name]) ) {
$_POST[field_name] = implode(',', $_POST[field_name]);
}
?>
$name = preg_replace('/name=("|\')/', '', $new_match2);
$name = str_replace('[]', '', $name); /* <- insert this line */
$emailbodytemplate = $rows[0]->emailtemplate;
Hi suckerhead,
Yes, that's good for the 'name' attributes (technically the 'id' attributes don't need the brackets and they should all be unique e.g. id='music_jazz' or id='music_1' but it probably won't make any real difference unless you use the ids in css or javascript).
I think that you now need to make some code hacks to have array fields work properly in ChronoForms v2.1:
In the Form Code tab paste in the 'On Submit code - before sending email:' box.
<?php
if ( is_array($_POST[field_name]) ) {
$_POST[field_name] = implode(',', $_POST[field_name]);
}
?>
$name = preg_replace('/name=("|\')/', '', $new_match2);
$name = str_replace('[]', '', $name); /* <- insert this line */
$emailbodytemplate = $rows[0]->emailtemplate;
<?php
if ( is_array($_POST[music]) ) {
$_POST[music] = implode(',', $_POST[music]);
}
?>
What kind of music do you listen?(can multiple select) <br />
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input name="music" type="checkbox" value="jazz" />
Jazz</td>
<td><input name="music" type="checkbox" value="rock" />
Rock</td>
<td><input name="music" type="checkbox" value="pop" />
Pop</td>
</tr>
<tr>
<td><input name="music" type="checkbox" value="Rap" />
Rap</td>
<td><input name="music" type="checkbox" value="hiphop" />
Hip Hop </td>
<td><input name="music" type="checkbox" value="classic" />
Classical</td>
</tr>
<tr>
<td><input name="music" type="checkbox" value="instrumental" />
Instrumental</td>
<td><input name="music" type="checkbox" value="Heavy Metal" />
Heavy Metal </td>
<td><input name="music" type="checkbox" value="ballad" />
Ballad</td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
<td><input name="music[]" type="checkbox" value="jazz" />Jazz</td>
Bob
$_POST[$name] = str_replace('[]','',$_POST[$name]);
if ( is_array($_POST[$name]) ) {
$_POST[$name] = implode(',', $_POST[$name]);
}
What kind of music do you listen?(can multiple select) <br />
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input name="music[]" type="checkbox" value="jazz" />
Jazz</td>
<td><input name="music[]" type="checkbox" value="rock" />
Rock</td>
<td><input name="music[]" type="checkbox" value="pop" />
Pop</td>
</tr>
<tr>
<td><input name="music[]" type="checkbox" value="Rap" />
Rap</td>
<td><input name="music[]" type="checkbox" value="hiphop" />
Hip Hop </td>
<td><input name="music[]" type="checkbox" value="classic" />
Classical</td>
</tr>
<tr>
<td><input name="music[]" type="checkbox" value="instrumental" />
Instrumental</td>
<td><input name="music[]" type="checkbox" value="Heavy Metal" />
Heavy Metal </td>
<td><input name="music[]" type="checkbox" value="ballad" />
Ballad</td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
<?php
if ( is_array($_POST[music]) ) {
$_POST[music] = implode(',', $_POST[music]);
}
?>
Did you try my solution above ?
Max
How does the email looks like after applying my hack ?
<?php
if ( is_array($_POST[music]) ) {
$_POST[music] = implode(',', $_POST[music]);
}
?>
Hi Suckerhead,
I think I have this working smoothly (fingers crossed). There are several places where you need to deal with the array that is returned by checkbox inputs. The changes are pretty simple and are along the lines described here but rather than try and explain them I've attached a couple of modified files for ChronoForms 2.1.4 - chronocontact.php and admin.chronocontact.php Make sure that you have copies of the distribution files then overwrite your installation with these two.
These files should fix the following problems:
+ Checkbox inputs only show the final entry
+ Field name shown as 'name[]' on Create table
+ Incomplete SQL error on Create table
+ Show checkbox arrays as comma separated lists in e-mails and database tables.
Please let me know if you have any problems and I'll look again - sorry this has taken so long, it's been a busy week.
Bob
[file name=chronocontact_checkbox.zip size=6927]http://www.chronoengine.com/components/com_fireboard/uploaded/files/chronocontact_checkbox.zip[/file]
<?php
if ( is_array($_POST[abc]) ) {
$_POST[abc] = implode(',', $_POST[abc]);
}
?>
Hi Suckerhead,
Ah! I may have found it - please test with 'E-mail the results' set to 'Yes' (I know you don't want to do this but that's the one difference between my form and yours).
Also leave out the code in #3a below as that should already be in the amended files.
If this works then I'll make a change to the files so that it works with or without the e-mail option.
Bob
Hi suckerhead,
Try this version. Both files are included in case anyone else tries it but only chronocontact.php is changed from the previous version.
This should work with any single dimension array in a form - that's what you are using. However, it won't work for multiple dimension arrays e.g. if you name all your form fields "form['some_name']" and among them have some checkboxes with names like "form['some_array[]']" That would need a further mod.
Forms like this are pretty rare - but sometimes it can be convenient to sweep up form values in an array for further processing.
Bob [file name=chronocontact_checkbox-cf27fcaa41b8fe861c763c88700b3d5a.zip size=6992]http://www.chronoengine.com/components/com_fireboard/uploaded/files/chronocontact_checkbox-cf27fcaa41b8fe861c763c88700b3d5a.zip[/file]<br><br>Post edited by: GreyHead, at: 2007/06/29 16:02
<script type="text/javascript">
function checkboxlimit(checkgroup, limit){
var checkgroup=checkgroup
var limit=limit
for (var i=0; i<checkgroup.length; i++){
checkgroup[i].onclick=function(){
var checkedcount=0
for (var i=0; i<checkgroup.length; i++)
checkedcount+=(checkgroup[i].checked)? 1 : 0
if (checkedcount>limit){
alert("You can only select a maximum of "+limit+" items")
this.checked=false
}
}
}
}
</script>
......
<tr>
<td valign="top"><p><strong>5. Where do you meet singles</strong></p>
<p>Choose your top three</p></td>
<td valign="top"><input type="checkbox" name="Q5" value="Pubs & Clubs"/>
Pubs & Clubs<br />
<input type="checkbox" name="Q5" value="Online Dating"/>
Online Dating<br />
<input type="checkbox" name="Q5" value="Speed Dating"/>
Speed Dating<br />
<input type="checkbox" name="Q5" value="Social Clubs"/>
Social Clubs<br />
<input type="checkbox" name="Q5" value="Blind Dates"/>
Blind Dates<br />
<input type="checkbox" name="Q5" value="Friends Parties"/>
Friends Parties<br />
<input type="checkbox" name="Q5" value="Mobile Dating"/>
Mobile Dating<br />
<input type="checkbox" name="Q5" value="Sports Clubs/Salsa Nights"/>
Sports Clubs/Salsa Nights<br />
<input type="checkbox" name="Q5" value="Singles party"/>
Singles party<br />
<input type="checkbox" name="Q5" value="Facebook or MySpace"/>
Facebook or MySpace<br />
<br /> </td>
</tr>
<tr>
......
<script type="text/javascript">
checkboxlimit(document.ChronoContact_whatsingleswant.Q5, 3)
</script>
checkboxlimit(document.ChronoContact_whatsingleswant.Q5, 3)
Q5[]