Condition on checkbox in Joomla
Posted: Fri Sep 04, 2009 1:30 pm
I have a MVC pattern controller for user registration. On the registration page, the form fields are getting displayed from the database. This is the function that validates the form.
function _validateProfile($post = array()){
//Part of code here
// Bind result from previous post into the field object
if(! empty($data)){
foreach($groups as $group){
$fields = $group->fields;
for($i = 0; $i <count($fields); $i++){
$fieldid = $fields[$i]->id;
$fieldname = $fields[$i]->name;
$isRequired = $fields[$i]->required;
$fieldType = $fields[$i]->type;
//$errMsg[] = 'Field entry \''.$fieldname.'\' : '.$isRequired.' : '.$fieldType;
if($isRequired == 1){
if($fieldType == 'date'){
if(JString::trim($data['field'.$fieldid][0]) == '' || JString::trim($data['field'.$fieldid][2]) == ''){
//Display error Message
}
} else {
if(empty($data['field'.$fieldid])){
//Display error Message
}
}//end if else
}//ebd if
}//end for i
}//end foreach
}
*/
}//end if
//$errMsg[] = 'Testing error.';
return $errMsg;
}
My question is, The function above is able to validate the form. I have 3 checkboxes with Id : field33 . When I click on one checkbox with value = "ABC" , it should run a insert query and send that selected checkbox value to the database. I know how to insert, but I am not able to validate the form and check which checkbox is being selected.
Do I need to write some if statement? I tried that but it display a blank white page. Could someone please help me with the conditional statement, and where I should put it to make it work.
Thank you
function _validateProfile($post = array()){
//Part of code here
// Bind result from previous post into the field object
if(! empty($data)){
foreach($groups as $group){
$fields = $group->fields;
for($i = 0; $i <count($fields); $i++){
$fieldid = $fields[$i]->id;
$fieldname = $fields[$i]->name;
$isRequired = $fields[$i]->required;
$fieldType = $fields[$i]->type;
//$errMsg[] = 'Field entry \''.$fieldname.'\' : '.$isRequired.' : '.$fieldType;
if($isRequired == 1){
if($fieldType == 'date'){
if(JString::trim($data['field'.$fieldid][0]) == '' || JString::trim($data['field'.$fieldid][2]) == ''){
//Display error Message
}
} else {
if(empty($data['field'.$fieldid])){
//Display error Message
}
}//end if else
}//ebd if
}//end for i
}//end foreach
}
*/
}//end if
//$errMsg[] = 'Testing error.';
return $errMsg;
}
My question is, The function above is able to validate the form. I have 3 checkboxes with Id : field33 . When I click on one checkbox with value = "ABC" , it should run a insert query and send that selected checkbox value to the database. I know how to insert, but I am not able to validate the form and check which checkbox is being selected.
Do I need to write some if statement? I tried that but it display a blank white page. Could someone please help me with the conditional statement, and where I should put it to make it work.
Thank you