public function execute()
{
parent::execute();
// get parameters
$formId = trim(\SpoonFilter::getPostValue('form_id', null, '', 'int'));
$fieldId = trim(\SpoonFilter::getPostValue('field_id', null, '', 'int'));
// invalid form id
if (!BackendFormBuilderModel::exists($formId)) {
$this->output(self::BAD_REQUEST, null, 'form does not exist');
} else {
// invalid fieldId
if (!BackendFormBuilderModel::existsField($fieldId, $formId)) {
$this->output(self::BAD_REQUEST, null, 'field does not exist');
} else {
// get field
$field = BackendFormBuilderModel::getField($fieldId);
// submit button cannot be deleted
if ($field['type'] == 'submit') {
$this->output(self::BAD_REQUEST, null, 'submit button cannot be deleted');
} else {
// delete field
BackendFormBuilderModel::deleteField($fieldId);
// success output
$this->output(self::OK, null, 'field deleted');
}
}
}
}