multiple checkbox , only record last answer?

Post any questions you may have here

multiple checkbox , only record last answer?

Postby suckerhead on Mon Jun 25, 2007 5:12 pm

i have a form with checkbox (can select multiple answer)

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] Image
suckerhead
Junior Boarder
 
Posts: 22
Joined: Wed Jun 20, 2007 9:11 am

Re:multiple checkbox , only record last answer?

Postby admin on Mon Jun 25, 2007 5:24 pm

Right, because first you need to name your boxes as music[] and not only music!!

please try this and let me know the effect on the email results and the database record

Cheers

max
ChronoForms Developer Thanks for using ChronoForms.
If you have any problems with ChronoForms please tell us.
If you like ChronoForms please post a review at Joomla.org
Want users to submit their content to your website ? try Submit Story
Want to list/edit/delete your data ? try ChronoConnectivity
User avatar
admin
Platinum Boarder
 
Posts: 1974
Joined: Mon Aug 14, 2006 5:29 am

Re:multiple checkbox , only record last answer?

Postby suckerhead on Mon Jun 25, 2007 5:44 pm

you meant i have to name all the check box music[]?
suckerhead
Junior Boarder
 
Posts: 22
Joined: Wed Jun 20, 2007 9:11 am

Re:multiple checkbox , only record last answer?

Postby suckerhead on Mon Jun 25, 2007 6:03 pm

suckerhead wrote:you meant i have to name all the check box music[]?


still error

if i sellect jazz, rock and ballad, i want the result on the database (table music) is jazz, rock, ballad

please see attached my file?

can you please edit for me? [file name=check-9e339f1a8c887e6e42ab798963237fe4.txt size=1112]http://www.chronoengine.com/components/com_fireboard/uploaded/files/check-9e339f1a8c887e6e42ab798963237fe4.txt[/file]
suckerhead
Junior Boarder
 
Posts: 22
Joined: Wed Jun 20, 2007 9:11 am

Re:multiple checkbox , only record last answer?

Postby GreyHead on Mon Jun 25, 2007 7:17 pm

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.
Code: Select all
<?php
if ( is_array($_POST[field_name]) ) {
$_POST[field_name] = implode(',', $_POST[field_name]);
}
?>

If you use templates, then to get them to work correctly open up chronocontact.php and go to line 143 and insert a new line after it .
Code: Select all
$name = preg_replace('/name=("|\')/', '', $new_match2);
$name = str_replace('[]', '', $name); /* <- insert this line */
$emailbodytemplate = $rows[0]->emailtemplate;


Bob<br><br>Post edited by: GreyHead, at: 2007/06/25 15:21
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
 
Posts: 3201
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Re:multiple checkbox , only record last answer?

Postby admin on Mon Jun 25, 2007 7:29 pm

so, how is it after applying Bob's hack?

Cheers

Max
ChronoForms Developer Thanks for using ChronoForms.
If you have any problems with ChronoForms please tell us.
If you like ChronoForms please post a review at Joomla.org
Want users to submit their content to your website ? try Submit Story
Want to list/edit/delete your data ? try ChronoConnectivity
User avatar
admin
Platinum Boarder
 
Posts: 1974
Joined: Mon Aug 14, 2006 5:29 am

Re:multiple checkbox , only record last answer?

Postby suckerhead on Tue Jun 26, 2007 11:00 am

GreyHead wrote: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.
Code: Select all
<?php
if ( is_array($_POST[field_name]) ) {
$_POST[field_name] = implode(',', $_POST[field_name]);
}
?>

If you use templates, then to get them to work correctly open up chronocontact.php and go to line 143 and insert a new line after it .
Code: Select all
$name = preg_replace('/name=("|\')/', '', $new_match2);
$name = str_replace('[]', '', $name); /* <- insert this line */
$emailbodytemplate = $rows[0]->emailtemplate;


Bob<br><br>Post edited by: GreyHead, at: 2007/06/25 15:21


Hi Bob and Max,

thanks for your reply,

Right now i'm using version 2.0, and have another form running. is it ok for the current running form if i just uninstall and install the new version, or i have to backup the form code?

sorry i'm asking to much, cos i dont have knownledge in php.

correct me if i'm wrong,
i have to use version 2.1 and
i use 'name' attribute with 'fieldname[]' and put the code you give on the submit code.

how about templates? what is that?
is it better to put code on the template or put code on submit code

please info.

thanks
suckerhead
Junior Boarder
 
Posts: 22
Joined: Wed Jun 20, 2007 9:11 am

Re:multiple checkbox , only record last answer?

Postby suckerhead on Tue Jun 26, 2007 12:57 pm

:( :blink:

Bob,
still can't.
here's my step

first,
put the php code on submit code before sending email

the code like this :
Code: Select all
<?php
if ( is_array($_POST[music]) ) {
$_POST[music] = implode(',', $_POST[music]);
}
?>



second,
change (input more code) the chronocontact.php line 143


and third,
my html form code like this

Code: Select all
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>



may be i'm misunderstand or not understand your guide?

can you make corection file (which code should i use on form tag or on submit code) for my form like that above and upload the file for me?

thanks again.
suckerhead
Junior Boarder
 
Posts: 22
Joined: Wed Jun 20, 2007 9:11 am

Re:multiple checkbox , only record last answer?

Postby GreyHead on Tue Jun 26, 2007 3:18 pm

Hi suckerhead,

The first problem is that you've taken the '[]'s out of the name attributes again. You do need these; they allow the form to pass an array of values with all the results instead of just a single value for the last checkbox. The other fixes are to let ChronoForms handle the array.

So your entries need to be like this:
Code: Select all
<td><input name="music[]" type="checkbox" value="jazz" />Jazz</td>
Bob
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
 
Posts: 3201
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Re:multiple checkbox , only record last answer?

Postby admin on Tue Jun 26, 2007 4:40 pm

Hi,

The solution is :

#1- u must use music[] for all ur checkboxes names
#2- hack chronocontact.php by adding these lines :
Code: Select all
$_POST[$name] = str_replace('[]','',$_POST[$name]);
if ( is_array($_POST[$name]) ) {
$_POST[$name] = implode(',', $_POST[$name]);
}


"UNDER" these lines :
#129
#144
#179
ChronoForms Developer Thanks for using ChronoForms.
If you have any problems with ChronoForms please tell us.
If you like ChronoForms please post a review at Joomla.org
Want users to submit their content to your website ? try Submit Story
Want to list/edit/delete your data ? try ChronoConnectivity
User avatar
admin
Platinum Boarder
 
Posts: 1974
Joined: Mon Aug 14, 2006 5:29 am

Re:multiple checkbox , only record last answer?

Postby suckerhead on Tue Jun 26, 2007 5:48 pm

Hi Guys,

i'm using chrono engine version 2.1 and joomla 10.0.12 now

still not working (sorry..) after follow your instruction

please info me which one is wrong, with this step

#1 hack the chronocontact.php (file attached) <<< can you check the file please :(

#2 make new form, i put back the []'s on all names
Code: Select all
 
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>


#3 put this code on submit code (before sending emails)
Code: Select all
<?php
if ( is_array($_POST[music]) ) {
$_POST[music] = implode(',', $_POST[music]);
}
?>


#4 save the form
#5 create table
>>>> the colom name for the music music[] << is it correct?
and when i press create table, appear windows pop up "Query was Empty SQL="

that's my last step.. so it did not create table on database.

until this step,
please info me is there something i miss or something wrong with the code (form code and chrono_hack.php)
suckerhead
Junior Boarder
 
Posts: 22
Joined: Wed Jun 20, 2007 9:11 am

Re:multiple checkbox , only record last answer?

Postby admin on Tue Jun 26, 2007 6:40 pm

Did you try my solution above ?

Max
ChronoForms Developer Thanks for using ChronoForms.
If you have any problems with ChronoForms please tell us.
If you like ChronoForms please post a review at Joomla.org
Want users to submit their content to your website ? try Submit Story
Want to list/edit/delete your data ? try ChronoConnectivity
User avatar
admin
Platinum Boarder
 
Posts: 1974
Joined: Mon Aug 14, 2006 5:29 am

Re:multiple checkbox , only record last answer?

Postby GreyHead on Wed Jun 27, 2007 12:06 am

Hi suckerhead,

When I have a few minutes I'll create a full working example of this and make sure that it all works together. hHopefully later this evening.

Bob
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
User avatar
GreyHead
Platinum Boarder
 
Posts: 3201
Joined: Tue May 29, 2007 10:15 pm
Location: Brittany

Re:multiple checkbox , only record last answer?

Postby suckerhead on Wed Jun 27, 2007 9:45 am

admin wrote:Did you try my solution above ?

Max


I did,Max. the last post i forget to attached the file
here's i attached the file.

If there are a question like this (jpg attached)? how it would be?
[file name=chrono_hack.zip size=3049]http://www.chronoengine.com/components/com_fireboard/uploaded/files/chrono_hack.zip[/file] Image
suckerhead
Junior Boarder
 
Posts: 22
Joined: Wed Jun 20, 2007 9:11 am

Re:multiple checkbox , only record last answer?

Postby admin on Wed Jun 27, 2007 7:16 pm

How does the email looks like after applying my hack ?
ChronoForms Developer Thanks for using ChronoForms.
If you have any problems with ChronoForms please tell us.
If you like ChronoForms please post a review at Joomla.org
Want users to submit their content to your website ? try Submit Story
Want to list/edit/delete your data ? try ChronoConnectivity
User avatar
admin
Platinum Boarder
 
Posts: 1974
Joined: Mon Aug 14, 2006 5:29 am

Next

Return to Questions & Answers

Who is online

Users browsing this forum: No registered users and 3 guests