Backend\Modules\FormBuilder\Engine\Model::existsField PHP Méthode

existsField() public static méthode

Does a field exist (within a form).
public static existsField ( integer $id, integer $formId = null ) : boolean
$id integer Id of a field.
$formId integer Id of a form.
Résultat boolean
    public static function existsField($id, $formId = null)
    {
        $id = (int) $id;
        // exists
        if ($formId === null) {
            return (bool) BackendModel::getContainer()->get('database')->getVar('SELECT 1
                 FROM forms_fields AS ff
                 WHERE ff.id = ?
                 LIMIT 1', $id);
        }
        // exists and ignore an id
        return (bool) BackendModel::getContainer()->get('database')->getVar('SELECT 1
             FROM forms_fields AS ff
             WHERE ff.id = ? AND ff.form_id = ?
             LIMIT 1', array($id, (int) $formId));
    }

Usage Example

Exemple #1
0
 /**
  * Execute the action
  */
 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);
             if ($field['type'] == 'radiobutton') {
                 $values = array();
                 foreach ($field['settings']['values'] as $value) {
                     $values[] = $value['label'];
                 }
                 $field['settings']['values'] = $values;
             }
             // success output
             $this->output(self::OK, array('field' => $field));
         }
     }
 }
All Usage Examples Of Backend\Modules\FormBuilder\Engine\Model::existsField