So this is what i want to do and this is what my fields
table looks like :
|-----------------------------|
|id | field | is_required|
|-----------------------------|
|1 | email | yes |
|-----------------------------|
|2 | phone | no |
|-----------------------------|
now i have created a view for this table using gii, which has an option to delete field value
, now what i want to do is in my actionDelete()
i want to check if the value that the user is trying to delete is required or not (if the table's is_required
field is yes
or no
, if it is yes
then the field is required, if it is no
then the field is not required), if the field is required i want to show an alert that "this field can't be deleted as it is a required field" else delete.
And this is what i have done so far in my controller:
public function actionDelete($id)
{
$check=Fields::model()->findByAttributes(array('id'=>$id));
$required=$check->is_required;
if($required =='no'){
$this->loadModel($id)->delete();
}elseif($required =='yes'){
echo "<script>alert('This field cannot be deleted.!');</script>";
}
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
but this is not working can any of you point me in the right direction..? Thanks in advance.