songohan
Posts: 89
|
| Posted: 07/14/2008, 5:49 AM |
|
First, why are some topics locked?
I have question on: http://forums.yessoftware.com/posts.php?post_id=97020
question is, how to correctly check checkboxes based on records in my database when I decide to show data?
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/15/2008, 10:43 AM |
|
Hi
Have you been able to successfully save the multiple check boxes into one data field as Walter demontrates?
I have got code that will re-check them all after the data field is retrieveed from the database.
It does require modification to the CCS Classes.php file. I can provide that code to you is you are interested.
Let me know.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
songohan
Posts: 89
|
| Posted: 07/15/2008, 12:32 PM |
|
Quote jjrjr1:
Have you been able to successfully save the multiple check boxes into one data field as Walter demontrates?
Did not have time to try jet but code seems ok, as Walters code usualy is :)
Quote jjrjr1:
I have got code that will re-check them all after the data field is retrieveed from the database.
It does require modification to the CCS Classes.php file. I can provide that code to you is you are interested.
Yes please, if you could share the code it would be great!
Many thnx,
Andrej
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/16/2008, 12:10 PM |
|
Ok
First here is how you put the data into the database field. It is similar to Walter's but in order to get the data back out it must be delimited with something. So you can use this in the
on validate event for your check box control:
This example was a database field of users interests where they of course can have several and when you recall the record I wanted all the interests checked again.
Of course you must have your checkbox table built and attached to the control
The individual check boxes values need to be delimited with something in order to get them back out. This code creates comma delimited quoted string values from the boxes checked and puts them into the data table control.
Below: On Validate for a multi check box called usr_interests
$JRinterests = CCGetParam("usr_interests");
$i=0;
while ($JRinterests[$i]){
$JRdbinterests='"'.$JRinterests[$i].'"'.$Comma.$JRdbinterests;
$Comma=",";
$i++;
}
$Container->usr_interests->SetValue($JRdbinterests);
Since this is done in the on validate event, the data is prepared properly and placed into the database with the quoted, comma delimited values that matched the checked values.
Now In order to retrieve these values for proper display and cause all the original boxes checked to display you must create a before show event for your check box control and modify Classes.php
Here is the before show event for your check box control. In this example it is named the same as above usr_interests. It is important that is is a global variable.
global $JRcheckedvalues;
$JRcheckedvalues=$Container->usr_interests->GetValue();
Now locate the following body of code in Classes.php and replace it with this. I thought it would be easier to include the entire case statement rather than try and show each individual line. be sure the entire case statement is replaced with this. You will notice that the modifications will allow the control to operate normally for non multi check box items. In case you have more that one multi checked items per form, some modifications will have to be made to this code to support that. I have not had a need to do that yet but is should be simple.
case ccsCheckBoxList:
$BlockToParse = "CheckBoxList " . $this->Name;
$Tpl->SetBlockVar($BlockToParse, "");//echo $this->Values[0][0]." ".$this->Values[1][0];
if(is_array($this->Values))
{
for($i = 0; $i < sizeof($this->Values); $i++)
{global $JRcheckedvalues; // Must be a comma delimited string containing Bound Values
$Value = $this->Values[$i][0];
$this->Attributes->SetValue("optionNumber", $i + 1);
$this->Attributes->Objects["optionNumber"]->Show();
$TextValue = CCToHTML(CCFormatValue($Value, $this->Format, $this->DataType));
$Text = $this->HTML ? $this->Values[$i][1] : CCToHTML($this->Values[$i][1]);
if ($this->Multiple && is_array($this->Value)) {
$Selected = "";//echo "Here";
foreach ($this->Value as $Val) {
if (CCCompareValues($Value,$Val, $this->DataType, $this->Format) == 0) {
$Selected = " " . $CheckedValue;
break;
}
}
} else {//echo "But Here No Multiple";
if ($JRcheckedvalues){//Do My Stuff $JRcheckedvalues must contain bound values from control
$JRcheckedvalues=" ".$JRcheckedvalues;
$Selected="";
$JRtest='"'.$this->Values[$i][0].'"';
// echo $JRtest;
if (strpos($JRcheckedvalues,$JRtest)){$Selected = $CheckedValue;}
}else{//do The Original Stuff
$Selected = (CCCompareValues($Value,$this->Value, $this->DataType, $this->Format) == 0) ? " " .$CheckedValue : "";}
}
$Tpl->SetVar("Value", $TextValue);
$Tpl->SetVar("Check", $Selected);
$Tpl->SetVar("Description", $Text);
$Tpl->Parse($BlockToParse, true);
}
}
break;
One of this days I will modify this to support multi-select list, boxes. Shoul be about the same.
Let me know how this works for you and if you have any questions.
Have fun.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/16/2008, 12:19 PM |
|
BTW.. The Control must be a CheckBoxList not CheckBox!!!!!
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/16/2008, 1:23 PM |
|
BTW again
If you have any other validations in your validate event, do not let this code run if there are any validation errors.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/16/2008, 1:28 PM |
|
Incidentally
This is one of the times I referenced in this post. When it is necessary to Modify CCS COde.
http://forums.yessoftware.com/posts.php?post_id=98541
I started that post to see if we all could share reasons to modify standard code or provide alternatives to doing that
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 07/18/2008, 11:07 AM |
|
Hey Songohan.
Have you tried this out yet?
Let me know.
Thanks
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
songohan
Posts: 89
|
| Posted: 07/20/2008, 3:42 PM |
|
Quote jjrjr1:
Hey Songohan.
Have you tried this out yet?
Let me know.
Thanks
First, thanks for your extensive answer.
Second, nope, I did not manage to try your solution jet Alot of other more urgent stuff apeared but I promise I'll let you and comunity know as soon as I try this.
Thanks again
Andrej
|
 |
 |
|