Пример #1
0
 public function storeResult($modelId = null)
 {
     if (Input::has('form')) {
         if (is_int(Input::get('form'))) {
             $rules = Former::getRules(Input::get('form'));
         } else {
             if (Input::has('combine_form')) {
                 $combine = true;
             } else {
                 $combine = false;
             }
             $rules = Former::getRulesByModel(Input::get('form'), $combine, $modelId);
         }
         $unsets = array();
         // Ajoute les nouvelles regles i18n
         foreach (Input::all() as $key => $input) {
             if (strpos($key, '_lang_')) {
                 $splitInput = explode("_", $key);
                 $rules[$key] = $rules[$splitInput[0]];
                 $unsets[$splitInput[0]] = $splitInput[0];
             }
         }
         // Supprime les anciennes regles
         foreach ($unsets as $value) {
             unset($rules[$value]);
         }
     } else {
         App::abort(500, "Form ID not found !");
     }
     // Using the Validator
     $validator = Validator::make(Input::except('_token'), $rules);
     // If errors we back to the previous forms with errors and old inputs
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     // Getting the form settings
     if ($form = Formr::find(Input::get('form'))) {
         // Action to use if the form is valid
         if ($form->finish_on == "email") {
             // Send a mail
             App::make('MailController')->formr(Input::alli18n());
         } else {
             if ($form->finish_on == "database") {
                 // Store in DB
             } else {
                 if ($form->finish_on == "model") {
                     Former::callModel($form, Input::alli18n());
                 } else {
                     App::abort(500, "No method found for send the form !");
                 }
             }
         }
     } else {
         $modelName = Input::get('form');
         $model = new $modelName();
         if (isset($model)) {
             if (Input::has('combine_form')) {
                 $combine = true;
             } else {
                 $combine = false;
             }
             $formParams = $model->formParams($combine);
         }
         if ($formParams['method'] == "email") {
             // Send a mail
             App::make('MailController')->formr(Input::alli18n());
         } else {
             if ($formParams['method'] == "database") {
                 // Store in DB
             } else {
                 if ($formParams['method'] == "model") {
                     return $model::formAction(Input::alli18n(), $modelId);
                 } else {
                     App::abort(500, "No method found for send the form !");
                 }
             }
         }
     }
     // Redirect back with success message
     return Redirect::back()->with('formSuccess', Lang::get('messages.form.success'));
 }
Пример #2
0
 /**
  * Add the corresponding rules to the field's attributes
  */
 private function addRules()
 {
     // Get the different rules assigned to this field
     $rules = Former::getRules($this->name);
     if (!$rules) {
         return false;
     }
     // Iterate through them and add the attributes
     foreach ($rules as $rule => $parameters) {
         switch ($rule) {
             case 'required':
                 $this->required();
                 break;
             case 'max':
                 $this->attributes['maxlength'] = array_get($parameters, 0);
                 break;
             case 'min':
                 $this->attributes['minlength'] = array_get($parameters, 0);
                 break;
             case 'numeric':
                 $this->attributes['pattern'] = '\\d+';
                 break;
             case 'not_numeric':
                 $this->attributes['pattern'] = '\\D+';
                 break;
             case 'alpha':
                 $this->attributes['pattern'] = '[a-zA-Z]+';
                 break;
             case 'between':
                 list($min, $max) = $parameters;
                 $this->attributes['min'] = $min;
                 $this->attributes['max'] = $max;
                 break;
             case 'in':
                 $this->attributes['pattern'] = '^(' . join('|', $parameters) . ')$';
                 break;
             case 'not_in':
                 $this->attributes['pattern'] = '(?:(?!^' . join('$|^', $parameters) . '$).)*';
                 break;
             case 'match':
                 $this->attributes['pattern'] = substr($parameters[0], 1, -1);
                 break;
         }
     }
 }