示例#1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postCreate()
 {
     $title = 'Add New ' . ucfirst($this->singleName);
     $controller = $this->name;
     $input_validation = $this->validateModel();
     if ($input_validation !== true) {
         $this->populateForm();
         Former::withErrors($input_validation);
         return View::make('site/' . $this->name . '/create', compact('title', 'controller'))->with('error', 'Not saved!');
     }
     $model = $this->saveModel();
     $model->created_by = Auth::user()->id;
     $model->save();
     $this->populateForm($model);
     $this->addDefaultTasks($model);
     return Redirect::to($this->name . '/' . $model->id . '/edit')->with('success', 'Saved!');
 }
示例#2
0
文件: Form.php 项目: iyoworks/former
 /**
  * Opens up magically a form
  *
  * @param  string $typeAsked  The form type asked
  * @param  array  $parameters Parameters passed
  * @return string             A form opening tag
  */
 public function open($typeAsked, $parameters)
 {
     $action = array_get($parameters, 0);
     $method = array_get($parameters, 1, 'POST');
     $attributes = array_get($parameters, 2, array());
     $secure = array_get($parameters, 3, false);
     // If classic form
     if ($typeAsked == 'open') {
         $type = Config::get('default_form_type');
     } else {
         // Look for HTTPS form
         if (str_contains($typeAsked, 'secure')) {
             $typeAsked = str_replace('secure', null, $typeAsked);
             $secure = true;
         }
         // Look for file form
         if (str_contains($typeAsked, 'for_files')) {
             $typeAsked = str_replace('for_files', null, $typeAsked);
             $attributes['enctype'] = 'multipart/form-data';
         }
         // Calculate form type
         $type = trim(str_replace('open', null, $typeAsked), '_');
         if (!in_array($type, $this->availableTypes)) {
             $type = Config::get('default_form_type');
         }
     }
     // Add the final form type
     $attributes = Helpers::addClass($attributes, 'form-' . $type);
     // Store it
     $this->type = $type;
     // Fetch errors if asked for
     if (Config::get('fetch_errors')) {
         Former::withErrors();
     }
     // Open the form
     $this->action = $action;
     $this->method = $method;
     $this->attributes = $attributes;
     $this->secure = $secure;
     return $this;
 }
示例#3
0
 /**
  * Update the specified resource in storage.
  *
  * @param $event, tickettype
  * @return View
  */
 public function postEdit($event, $tickettype)
 {
     $title = 'Edit ' . ucfirst($this->singleName) . ' Details - ' . $tickettype->name;
     $controller = $this->name;
     $input_validation = $this->validateModel();
     if ($input_validation !== true) {
         $this->populateForm();
         Former::withErrors($input_validation);
         return View::make('site/tickets/types/edit', compact('title', 'tickettype', 'controller'))->with('error', 'Not saved!');
     }
     $this->saveModel($event, $tickettype);
     $this->populateForm($tickettype);
     return View::make('site/tickets/types/edit', compact('title', 'tickettype', 'controller'))->with('success', 'Saved!');
 }
示例#4
0
 /**
  * Perform input validation
  * 
  * Checks wether a page variable is set in the sitemap and returns it
  * @return string
  */
 public static function validate()
 {
     $rules = Xysti::page('post_rules');
     if (is_array($rules)) {
         $validation = Validator::make(Input::all(), $rules);
     } else {
         return Xysti::error(500, 'Expecting post rules array.');
     }
     // If validation has failed
     if ($validation->fails()) {
         Session::flash('warning', 'Could not submit. Validation errors were found.');
         // @todo remove Former dependance
         Former::withErrors($validation);
         // Make the page without any more routes
         return Xysti::make();
         // @todo some mechanism to redirect on failure if that's prefered.
         //return Redirect::to(URI::current())->with_errors($validation);
     }
 }