Answer the question
In order to leave comments, you need to log in
What is the benefit of creating html forms in php classes?
Why create forms in php classes and describe each field there?
I don’t understand what the profit is if the same thing is calmly written in html, except that if you write the forms “by hand”, the web application page will load a little faster.
Answer the question
In order to leave comments, you need to log in
The simplest example is fast and convenient validation, for example, in django it is done like this
class AuthenticationForm(forms.Form):
username = forms.CharField(max_length=254)
password = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
form = AuthenticationForm(request.POST) #передаю в форму POST запросы, можно и GET и вообще все что угодно.
if AuthenticationForm.is_valid(): # если форма прошла валидацию, то делаем что то
pass
For automation, this is done, because the form still needs to be checked, saved and / or sent. In this case, only the form is described by hands, and everything else is automatic.
The reasons are banal - you have a form in HTML - consider the presentation layer, and business logic - models and services. Forms in the form of classes - the bridge between the two layers. It takes care of all those tedious things like binding values, binding form values on the model, transforming data from model format to presentation format (let's say the date model field can be transformed into several date and time inputs). Usually all these things can be reused from project to project, due to which the value of such things increases dramatically. Well, yes, the logic of processing forms in this regard does not depend on the presentation in any way.
Alas, I am not aware of the implementation of forms in the falcon, I worked closely only with Symfony Forms from what is more serious. A typical opinion about such components is about the same as yours, why, it’s complicated, simple things are too complicated ... But when it comes to the fact that after a year of development, you need to quickly add some functionality to all forms, for example ... recently they asked here - how to save the previous value and do it automatically, such things save. You can implement one simple extension, in fact, a decorator over inputs, specify for which types it should be used, and there already fence your logic. As a result, the time to implement new functionality is reduced in proportion to the size of the application. On serious projects without such things, life is generally hard and sad.
In a word, by choosing simplicity of implementation and rejection of all these unnecessary forms of builders, you lose control over the flexibility of the system and increase the time for adding new functionality in the future.
The reason is banal - less writing. Although it is also not small in classes, it is still smaller and easier to modify.
What is the time saving if for complex forms you have to create your own elements in special classes?
docs.phalconphp.com/ru/latest/reference/tutorial-i...
https://github.com/phalcon/invo/blob/master/app/li...
Yes, and how, for example, using this
https:/ /github.com/phalcon/vokuro/blob/master/app/...
Create such a simple form
getbootstrap.com/css/#forms
__
that's me to make a normal skeleton from form tags, using such solutions is really easy , fast and convenient. But it’s more difficult to move beyond the form skeleton somewhere than to write it in html.
For example, the result of executing
https://github.com/phalcon/vokuro/blob/master/app/...
will be like this (roughly...):
<form action="/" method="post">
<label for="email">Email</label>
<input type="text" name="email" placeholder="Email"/>
<label for="password">Password</label>
<input type="password" name="password" placeholder="Password"/>
<label for="remember">
<input type="checkbox" name="remember" checked/>
Remember
</label>
<input type="hidden" name="csrf" value="token ..."/>
<input type="submit" name="go" class="btn btn-success"/>
</form>
<form role="form">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<input type="file" id="exampleInputFile">
<p class="help-block">Example block-level help text here.</p>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Check me out
</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question