/**
  * @param $form_id
  */
 public function postEdit($form_id)
 {
     Coanda::checkAccess('webforms', 'edit');
     try {
         $form = $this->webFormsRepository->getForm($form_id);
         $has_added = false;
         $has_removed = false;
         if (Input::has('add_field') && Input::get('add_field') == 'true') {
             $field_type = Input::has('new_field_type') ? Input::get('new_field_type') : false;
             if (!$field_type) {
                 return Redirect::to(Coanda::adminUrl('forms/edit/' . $form->id));
             }
             $this->webFormsRepository->addField($form_id, $field_type);
             $has_added = true;
         }
         if (Input::has('remove_selected') && Input::get('remove_selected') == 'true') {
             $fields = Input::has('remove_fields') ? Input::get('remove_fields') : [];
             if (is_array($fields) && count($fields) > 0) {
                 foreach ($fields as $field_id) {
                     $this->webFormsRepository->removeField($form_id, $field_id);
                 }
             }
             $has_removed = true;
         }
         try {
             $this->webFormsRepository->storeForm($form_id, Input::all());
             if ($has_added) {
                 return Redirect::to(Coanda::adminUrl('forms/edit/' . $form->id))->with('field_added', true);
             }
             if ($has_removed) {
                 return Redirect::to(Coanda::adminUrl('forms/edit/' . $form->id))->with('fields_removed', true);
             }
             return Redirect::to(Coanda::adminUrl('forms/view/' . $form->id));
         } catch (ValidationException $exception) {
             if ($has_added) {
                 return Redirect::to(Coanda::adminUrl('forms/edit/' . $form->id))->with('field_added', true);
             }
             if ($has_removed) {
                 return Redirect::to(Coanda::adminUrl('forms/edit/' . $form->id))->with('fields_removed', true);
             }
             return Redirect::to(Coanda::adminUrl('forms/edit/' . $form->id))->with('error', true)->with('invalid_fields', $exception->getInvalidFields())->withInput();
         }
     } catch (WebFormNotFoundException $exception) {
         App::abort('404');
     }
 }