hi all,
how to save multiple value from several checkbox in one database field ?
i want to enter "Photo Gallery" and "Classifieds" into "features" field if user select both checkbox.
any one have the same difficulties?
please help me out.
TIA,
dwi
how to save multiple value from several checkbox in one database field ?
<input name="features" type="checkbox" class="radio" id="features" value="Photo Gallery" />
<input name="features" type="checkbox" class="radio" id="features" value="Classifieds" />
i want to enter "Photo Gallery" and "Classifieds" into "features" field if user select both checkbox.
any one have the same difficulties?
please help me out.
TIA,
dwi
First, you will need to play with the Auto generated code in the form, but mainly you have 2 elements with the same id which is a BIG mistake!!!
Max
Max
hi max,
thank you for the response.
but, sorry, i dont understand with your explanation. what do you mean by "big mistake" ??
can u give me some code just to make it clearer, please ?
regards,
dwi
thank you for the response.
but, sorry, i dont understand with your explanation. what do you mean by "big mistake" ??
can u give me some code just to make it clearer, please ?
regards,
dwi
Hi dwi,
The html standards forbid duplicate id's within a document see here. Most browsers don't check but duplication can cause problems.
Names generally also have to be unique, though checkboxes with shared names are allowed. I'm not sure how ChronoForms deals with the output in this case though.
The easy way to get round this is to give your checkboxes separate names and concatenate the answers with a little code hack.
Bob<br><br>Post edited by: GreyHead, at: 2007/06/17 17:02
The html standards forbid duplicate id's within a document see here. Most browsers don't check but duplication can cause problems.
Names generally also have to be unique, though checkboxes with shared names are allowed. I'm not sure how ChronoForms deals with the output in this case though.
The easy way to get round this is to give your checkboxes separate names and concatenate the answers with a little code hack.
Bob<br><br>Post edited by: GreyHead, at: 2007/06/17 17:02
hi bob,
thanks for the response, i just thought like that, but it involved with hundreds of checkboxes😟(
btw, many thanks for the answer.
regards,
dwi
thanks for the response, i just thought like that, but it involved with hundreds of checkboxes😟(
btw, many thanks for the answer.
regards,
dwi
Hi Dwi,
I hadn't realise that you had hundreds. If I have a moment later today I'll have a look and see what ChronoForms does with the checkbox results. It may need a hack to stop it overwriting the previous results - or it may be possible to use an array in the form like name='feature[]' to make the results easier to handle.
Bob
I hadn't realise that you had hundreds. If I have a moment later today I'll have a look and see what ChronoForms does with the checkbox results. It may need a hack to stop it overwriting the previous results - or it may be possible to use an array in the form like name='feature[]' to make the results easier to handle.
Bob
Hi dwi,
I've sorted out a hack that will do this. Even though duplicate checkbox names are allowed in the html they aren't passed in the form $_POST variable. To fix this replace name='feature' with name='feature[]', this creates an array of checked entries that is passes in $_POST.
You then need to find the for next loop in chronocontact.php where $html_message is created and make changes equivalent to the following
Note 1: My code here is fairly heavily re-factored to use 'cases' instead of the 'if' clauses in Max' code - but the logic is identical. You'll find the changed lines marked // ::HACK ::
I've trimmed any '[]' from the names list then imploded the entry to a comma separated list if it's an array.
Note 2: This hack only works with the default table formatted e-mail - if you are using a template, or saving to a database table you may need to make equivalent code changes elsewhere. (Though hopefully Max will pick this up in a future version.)
Bob
I've sorted out a hack that will do this. Even though duplicate checkbox names are allowed in the html they aren't passed in the form $_POST variable. To fix this replace name='feature' with name='feature[]', this creates an array of checked entries that is passes in $_POST.
You then need to find the for next loop in chronocontact.php where $html_message is created and make changes equivalent to the following
$i = 0;
$html_message = "<table cellpadding='0' cellspacing='0'
border='0' width='100%'>";
$col_names = array();
if ( !is_array($omittedlist) ) {
$omittedlist = array();
}
foreach ( $matches[0] as $match ) {
$new_match = preg_replace('/name=("|\')/i', '', $match);
$new_match2 = preg_replace('/("|\')/', '', $new_match);
$name = preg_replace('/name=("|\')/', '', $new_match2);
$name = str_replace('[]', '', $name); // :HACK ::
$name = trim($name);
if ( in_array($name, $col_names) || in_array($name, $omittedlist) ) {
continue;
} else {
$col_names[] = $name;
}
$field_namex = $name;
if ( trim($titlesvalues->$field_namex) != '' ) {
$field_namex = $titlesvalues->$field_namex;
}
$post = $_POST[$name]; // :HACK ::
if ( is_array($post) ) { // :HACK ::
$post = implode(',', $post); // :HACK ::
} // :HACK ::
$html_message .= "<tr height='10'>
<td width='40%' class='tablecell1'>$field_namex</td>
<td width='60%' class='tablecell2'>$post</td> // :HACK ::
</tr>";
$i++;
}
$html_message.= "</table>";
Note 1: My code here is fairly heavily re-factored to use 'cases' instead of the 'if' clauses in Max' code - but the logic is identical. You'll find the changed lines marked // ::HACK ::
I've trimmed any '[]' from the names list then imploded the entry to a comma separated list if it's an array.
Note 2: This hack only works with the default table formatted e-mail - if you are using a template, or saving to a database table you may need to make equivalent code changes elsewhere. (Though hopefully Max will pick this up in a future version.)
Bob
Hi All,
In order to achieve what DWI needs, we will add the 3lines of Bob's hack at the auto generated tab, over the generated code, just put this :
Thats all!!
Please let us know how it works for you!!
Cheers
Max
In order to achieve what DWI needs, we will add the 3lines of Bob's hack at the auto generated tab, over the generated code, just put this :
if ( is_array($_POST[field_name]) ) { // :HACK ::
$_POST[field_name] = implode(',', $_POST[field_name]); // :HACK ::
} // :HACK ::
Thats all!!
Please let us know how it works for you!!
Cheers
Max
This topic is locked and no more replies can be posted.