Loads a form and validates it (unless specified).
        If the form referenced has not been loaded, an attempt to create a form
        object using the information in the template will be made.
163614
def form(self, obj=None, form=None, name=None, template=None, var_name=None, validate_on_submit=True,\
        exit_on_failure=True, csrf_enabled=None):
        
        if not form or isinstance(form, str):
            if not name and isinstance(form, str):
                name = form
            if not name:
                name = request.endpoint.rsplit('.', 1)[1] if '.' in request.endpoint else request.endpoint
            if name not in self.forms:
                raise NoFormError("Cannot find form '%s'" % name)
            form = self.forms[name]
        if inspect.isclass(form):
            if isinstance(obj, dict):
                obj = DictObject(obj)
            if csrf_enabled is None:
                csrf_enabled = self.options["csrf_enabled"]
            form = form(obj=obj, meta={'csrf': csrf_enabled})

        current_context.data.form = form
        yield form

        if validate_on_submit and request.method == "POST":
            self.validate(form, exit_on_failure=exit_on_failure)
173865
def _construct_form(self, i, **kwargs):
        """"""
        form = super(MetadataFormset, self)._construct_form(i, **kwargs)
        # Monkey patch the form to always force a save.
        # It's unfortunate, but necessary because we always want an instance
        # Affect on performance shouldn't be too great, because ther is only
        # ever one metadata attached
        form.empty_permitted = False
        form.has_changed = lambda: True

        # Set a marker on this object to prevent automatic metadata creation
        # This is seen by the post_save handler, which then skips this
        # instance.
        if self.instance:
            self.instance.__seo_metadata_handled = True

        return form
158401
final public function validate($form)
    {
        $this->initializeValidator($form);

        $formObject = $this->formValidatorExecutor->getFormObject();
        $formObject->markFormAsSubmitted();
        $formObject->setForm($form);

        $this->validateGhost($form, false);

        $formObject->setFormResult($this->result);

        return $this->result;
    }
1290939
def load(self):
        
        self.inventory = SDBInventory(self.usr)
        self.forms = self.inventory.forms
718714
def form_valid(self, form):
        
        #noinspection PyAttributeOutsideInit
        self.object = form.save()

        # Index the link.
        for backend in get_search_backends():
            backend.add(self.object)

        #noinspection PyUnresolvedReferences
        return render_modal_workflow(
            self.request,
            None,
            '{0}/chosen.js'.format(self.template_dir),
            {'obj': self.get_json(self.object)}
        )
1059353
def get(self, request, *args, **kwargs):
        
        form_class = self.get_form_class()
        form = self.get_form(form_class)
        if form.is_valid():
            return self.form_valid(form)

        else:
            return self.form_invalid(form)
53733
protected function loadForm()
    {
        $form = $this->createForm();

        $bridge = $this->model->getBridgeFor('form', $form);

        $this->addFormElements($bridge, $this->model);

        $this->form = $bridge->getForm();
    }
686480
def form_valid(self, form, formsets):
        
        # check if it's a new object before it save the form
        new_object = False
        if not self.object:
            new_object = True

        instance = getattr(form, 'instance', None)
        auto_tags, changed_tags, old_tags = tag_handler.get_tags_from_data(
            form.data, self.get_tags(instance))
        tag_handler.set_auto_tags_for_form(form, auto_tags)

        with transaction.commit_on_success():
            self.object = self.save_form(form)
            self.save_formsets(form, formsets, auto_tags=auto_tags)

            url = self.get_object_url()
            self.log_action(self.object, CMSLog.SAVE, url=url)
            msg = self.write_message()

        # get old and new tags
        if not new_object and changed_tags and old_tags:
            tag_handler.update_changed_tags(changed_tags, old_tags)

        return self.success_response(msg)
1047883
def clean_form_template(self):
        
        form_template = self.cleaned_data.get('form_template', '')
        if form_template:
            try:
                get_template(form_template)
            except TemplateDoesNotExist:
                msg = _('Selected Form Template does not exist.')
                raise forms.ValidationError(msg)
        return form_template
849615
def post(self, request, **kwargs):
        
        forms = self.get_forms()
        if self.are_forms_valid(forms):
            return self.forms_valid(forms)
        else:
            return self.forms_invalid(forms)
915065
def form_valid(self, form):
        """"""

        self.object = form.save(commit=False)
        self.object.project = self.project
        self.object.save()

        # Good to make note of that
        messages.add_message(self.request, messages.SUCCESS, 'Stage %s created' % self.object.name)

        return super(ProjectStageCreate, self).form_valid(form)
524476
def use_form(form_class, request=None, **top_kwargs):
    

    def validated_form(request, **kwargs):
        # import ipdb; ipdb.set_trace()
        data = request.query_params.dict() if request.method in ['GET'] else request.data
        if isinstance(data, QueryDict):
            form = form_class(data={**data.dict(), **kwargs})
        elif isinstance(data, dict):
            form = form_class(data={**data, **kwargs})
        else:
            form = form_class(data=data, **kwargs)
        form.is_valid(raise_exception=True)
        return form

    if request:
        kwargs = {}
        if request.resolver_match:
            kwargs = {**request.resolver_match.kwargs}
        if top_kwargs:
            kwargs = {**kwargs, **top_kwargs}

        return validated_form(request, **kwargs).validated_data

    def wrap(func):
        def method_wrap(view, request, *args, **kwargs):
            form = validated_form(request, **kwargs)
            if hasattr(view, 'log'):
                form.log = view.log
            return func(view, form.validated_data, *args, **kwargs)

        def function_wrap(request, *args, **kwargs):
            form = validated_form(request, **kwargs)
            return func(form.validated_data, *args, **kwargs)

        def inner(*args, **kwargs):
            is_method = isinstance(args[0], APIView)
            return (method_wrap if is_method else function_wrap)(*args, **kwargs)

        return inner

    return wrap
899323
function validateForm(form, cb) {

  async.series([function(callback) {
    fs.exists(form, function(exists) {
      if (exists) {
        callback(null);
      } else {
        callback('File ' + path.basename(form) + ' referenced by metadata.json does not exists');
      }
    });
  },
    function(callback) {
      validateJSonStructure(form, callback);
    }
  ], function(err, data) {
    cb(err, data);
  });
}
1374558
def form_invalid(self, form):
        
        if self.request.is_ajax():
            return self.render_json_response(self.get_error_result(form))
        return super(AjaxFormMixin, self).form_invalid(form)
1331876
protected function InitForm()
    {
        $this->html = $this->LoadElement();
        $name = 'Html';
        $this->AddRichTextField($name, $this->html->GetHtml());
        $this->AddCssClassField();
        $this->AddCssIDField();
        $this->AddCacheLifetimeField();
        $this->AddSubmit();
    }
483818
def get_form(self, form_class):
        """"""
        if not hasattr(self, '_form'):
            kwargs = self.get_form_kwargs()
            self._form = form_class(**kwargs)
        return self._form
541948
def fill_form(form, data):
    
    for (key, value) in data.items():
        if hasattr(form, key):
            if isinstance(value, dict):
                fill_form(getattr(form, key), value)
            else:
                getattr(form, key).data = value
    return form