Use wtfroms without using flask-bootstrap - html

I'm starting to create a login-signup web page for a project and for that I would like to use "wtforms" but I can't find any examples without using the flask-bootstrap library.
Can I use wtform without flask-bootstrap?
I did some experiments but it doesn't seem to work.
This is my code:
HTML:
<div class="login-form">
<form action="/registration" method="POST">
<h2 class="text-center">Registrazione</h2>
<div class="form-group has-error">
<input type="text" class="form-control" name="nome" placeholder="Nome" required="required">
</div>
<div class="form-group has-error">
<input type="text" class="form-control" name="cognome" placeholder="Cognome" required="required">
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" placeholder="E-mail" required="required">
</div>
<div class="form-group">
<input type="password" class="form-control" name="password" placeholder="Password" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="la password deve contenere almeno un numero, una lettera maiuscola, una minuscola e deve essere almeno di 8 carateri" required="required">
</div>
<div class="form-group">
<input type="password" class="form-control" name="confermaPsw" placeholder="Conferma password" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="la password deve contenere almeno un numero, una lettera maiuscola, una minuscola e deve essere almeno di 8 carateri" required="required">
</div>
<div class="form-group">
<select class="form-control" name="ruolo" id="sel1" required="required">
<option>SW</option>
<option>PM</option>
<option>PE</option>
</select>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-lg btn-block">Registrati</button>
</div>
</form>
Python:
class RegisterForm(FlaskForm):
name = StringField('name', validators=[InputRequired(), Length(min=4, max=15)])
surname = StringField('surname', validators=[InputRequired(), Length(min=4, max=15)])
email = StringField('email', validators=[InputRequired(), Length(max=50)])
password = PasswordField('password', validators=[InputRequired(), Length(min=8, max=80)])
ruolo = StringField('urole', validators=[InputRequired()])
#app.route('/registration', methods=['POST', 'GET'])
def registration():
# se tutti gli input rispettano i prerequisiti di validazione, aggiungi utente
form = RegisterForm()
if request.method == 'POST':
if form.validate_on_submit():
hashed_password = generate_password_hash(form.password.data, method='sha256')
new_user = User(name=form.nome.data, surname=form.cognome.data, email=form.email.data, password=hashed_password, urole=form.ruolo.data)
db.session.add(new_user)
db.session.commit()
return '<h1>New user has been created!</h1>'
return '<h1>post send but no validate!</h1>'
return render_template("registration.html", form=form)
EDIT: I need to have the same formatting I had before using WTForms

I'm looking for a solution for this exact question too, but all use flask-bootstrap and that is exactly what I don't want to use.
I've tried the following:
{{ form.firstname(class='form-control bg-white border-left-0 border-md', placeholder='Firstname') }}
outputs
<input class="form-control bg-white border-left-0 border-md" id="firstname" name="firstname" placeholder="Firstname" required type="text" value="">
This seems to work, well visually it seems to do what I want.

Related

Form Submit Button not work on Smartphone

I have an app developed in VueJs. I have a contact form. This form is working perfectly in different browsers, however when trying to use this form on a smartphone or tablet it doesn't work.
And I tried to implement it in two ways but the problem persists. implementation 1:
<form #submit.prevent="send_message">
<form-group>
<label for="name" class="required">Nome:</label>
<input
type="text"
name="name"
id="name"
class="form-control"
required
v-model="msg.name"
placeholder="Seu nome completo"
/>
</form-group>
<form-group>
<label for="email" class="required">E-mail:</label>
<input
type="email"
name="email"
id="email"
class="form-control"
required
placeholder="Seu e-mail"
v-model="msg.email"
/>
</form-group>
<form-group>
<label for="subject" class="required">Assunto :</label>
<input
type="text"
name="subject"
id="subject"
class="form-control"
placeholder="Assunto da Mensagem"
required
v-model="msg.subject"
/>
</form-group>
<form-group>
<label for="message" class="required">Mensagem:</label>
<textarea
name="message"
id="message"
class="form-control"
placeholder="Conteúdo da Mensagem"
required
v-model="msg.message"
/>
</form-group>
<p><span class="text-danger">*</span>Campos obrigatórios</p>
<button class="add btn btn-gradient-primary font-weight-bold todo-list-add-btn ml-0 ml-lg-2 mt-2 mt-lg-0" id="add-task">Add</button>
</form>
Just do your submit like this and it should work out:
{
methods: {
submit: function () {
// do you submit/code in here
}
}
}
Hopefully this helps you out!

HTML How to dissociate a button from the form it's in? [duplicate]

This question already has answers here:
How to prevent buttons from submitting forms
(20 answers)
Closed 2 years ago.
I have a HTML form, and a button inside of it, witch isn't submit.
And when i click it, it sends the form, and reloads the page. Witch i don't want.
I'd like to dissociate that button from the form it's in.
Google didn't helped much.
Here is the form :
<form action="" method="post">
<div class="form-group">
<label for="jdrName">Nom du jeu de rôle :</label>
<input type="text" class="form-control" name="jdrName"
placeholder="Nom du jeu">
</div>
<div class="form-group">
<label for="jdrGenre1">Genre associé au jeu</label>
<input type="text" class="form-control" name="jdrGenre1">
<button id="addGenre" class="btn btn-success">Ajouter un genre</button>
</div>
<div class="form-group">
<label for="jdrName">Date de sortie :</label>
<input type="date" class="form-control" name="gameRelease">
</div>
<div class="form-group">
<label for="jdrDescription">Description du jeu</label>
<textarea class="form-control" name="jdrDescription" rows="5"
placeholder="Entrez ici une description succinte du jeu"></textarea>
</div>
<div class="form-group">
<label for="jdrLink">Lien vers le site du jeu</label>
<input type="text" class="form-control" name="jdrLink">
</div>
<button type="submit" class="btn btn-primary">Valider</button>
</form>
Thanks !
You must precise that the button is of type="button", the default type being submit.

How to confirm to matching email fields?

I'm creating a "Event Form" where people should be able to sign-up for comming events.
I added two fields for email. One for them to write their email in and the second one to confirm the email.
I want them to write it twice to ensure that we are getting the right email.
When the email in field 2 (Bekräfta Email) is wrong they should get an error message.
But it seems like I'm doing something wrong with the code.
This is the HTML-Code:
<script type="text/javascript">
function openTerms(id) {
var terms = {"1":"Med detta villkor godkännes att Svenska Bostadsfonden Management AB får använda min personliga information så som,namn, telefonnummer, mail, arbetstitel, arbetsplats, postadress och besöksadress i syfte att...... I enlighet med GDPR och lagen och samtycke.......","2":"Terms of conditions bla bla bla","3":null,"4":null,"5":null,"6":null,"7":null};
var preview = window.open("", "", "height=700,width=800,scrollbars=yes,resizable=yes,toolbar=no,status=no,menu=no,titlebar=no,location=no,addressbar=no");
var html="<head><meta charset=\"UTF-8\"><style>body {margin: 0; padding: 20px;color: #333;font-family: Helvetica;font-size: 14px;}</style></head><body>" + terms[id] + "</body>";
preview.document.write(html);
}
</script>
<form id="up-form" name="form_8311ud1507fd3ad2e43278424bca0e4adc3bd" action="https://power.upsales.com/api/external/formSubmit" method="POST">
<div>
<label>Jag vill beställa</label>
<br>
<label><input type="checkbox" value="Aktuellt faktablad" name="Extra.1547544176421"> Aktuellt faktablad </label>
<label><input type="checkbox" value="Aktuell broschyr" name="Extra.1547544176421"> Aktuell broschyr </label>
</div>
<div>
<label>Jag vill beställa i egenskap av</label>
<br>
<select name="Extra.1547544378077">
<option></option>
<option value="Befintlig kund">Befintlig kund</option>
<option value="Intresserad investerare">Intresserad investerare</option>
<option value="Finansiell rådgivare">Finansiell rådgivare</option>
<option value="Media/analytiker">Media/analytiker</option>
<option value="Annat">Annat</option>
</select>
</div>
<div>
<label>Namn *</label>
<br>
<input maxlength="512" type="text" name="Contact.name" required="required">
</div>
<div class="email">
<label>Email *</label>
<br>
<input maxlength="512" type="email" id="up-email-input" autocomplete="off" name="Contact.email" required="required">
</div>
<div>
<label>Bekräfta Email *</label>
<br>
<input maxlength="512" type="text" name="Extra.1547643200666" required="required">
</div>
<div>
<label>Telefon *</label>
<br>
<input maxlength="512" type="text" id="up-client-name-input" name="Client.name" required="required">
</div>
<div>
<label>Postadress *</label>
<br>
<input maxlength="512" type="text" name="Extra.1547544152076" required="required">
</div>
<!-- REQUIRED FIELDS -->
<input type="hidden" name="formCid" value="8311">
<input type="hidden" name="formId" value="8311ud1507fd3ad2e43278424bca0e4adc3bd">
<input type="hidden" name="isFrame" value="false">
<input type="text" value="" name="validation" style="display: none;">
<!-- END OF REQUIRED FIELDS -->
<button type="submit">Skicka</button>
</form>
<script src="https://img.upsales.com/2XybO6NW9Y+uyQU9cm4CLw==/be.js"></script>
I added the following to the code:
<div class="email">
<label>Email *</label>
<br>
<input maxlength="512" type="email" id="up-email-input" autocomplete="off" name="Contact.email" required="required">
</div>
<div>
<label>Bekräfta Email *</label>
<br>
<input maxlength="512" type="text" name="Extra.1547643200666" required="required">
</div>
if (trim($fv->txt_Bekräfta Email) != $fv->txt_Email) {
$e->defineError("invalid_email", "Your Email address do not match", "txt_Bekräfta Email");
Seems like the following sequence does not work:
if (trim($fv->txt_Bekräfta Email) != $fv->txt_Email) {
$e->defineError("invalid_email", "Your Email address do not match", "txt_Bekräfta Email");

2 inputs with same classes have different appearances (HTML)

I have made a form with two inputs with the same classes but they have different appearances. They only get the same appearances if I change the type from "email" to "text". Is it a problem with the code or is it HTML5 that does it?
<form action="../../../redirect.html">
<input name="username" id="login-username" class="login-input pure-u-1" type="email" maxlength="96" tabindex="1" aria-required="true" value="" placeholder="Indtast din e-mail" title="Indtast din e-mail" autocorrect="off" spellcheck="false" required autofocus>
<input name="password" id="login-password" class="login-input pure-u-1" type="password" maxlength="96" tabindex="1" aria-required="true" value="" placeholder="Indtast din adgangskode" title="Indtast din adgangskode" autocorrect="off" spellcheck="false" required>
<button type="submit" formaction="../../../redirect.html" id="login-signing" class="pure-u-1 pure-button mbr-button-primary" value="Submit" tabindex="1">Login</button>
</form>
in your css file, it seems that it style input's that has class "pure-form" but you have used "login-input". so it seem's that the problem is about how to use your css style not about "HTML5".
this is the correct code:
<form action="../../../redirect.html">
<input name="username" id="login-username" class="pure-form pure-u-1" type="email" maxlength="96" tabindex="1" aria-required="true" value="" placeholder="Indtast din e-mail" title="Indtast din e-mail" autocorrect="off" spellcheck="false" required autofocus>
<input name="password" id="login-password" class="pure-form pure-u-1" type="password" maxlength="96" tabindex="1" aria-required="true" value="" placeholder="Indtast din adgangskode" title="Indtast din adgangskode" autocorrect="off" spellcheck="false" required>
<button type="submit" formaction="../../../redirect.html" id="login-signing" class="pure-u-1 pure-button mbr-button-primary" value="Submit" tabindex="1">Login</button>
</form>

HTML AngularJs CSS Form submit

I'm having a problem when I submit the form.
So.. I fill all data on the formulary then I click save... The data is correctly saved, but after the submit, the fields are cleaned and then the inputs receive the css because the form is already submitted. I would like to don't keep the formulary 'submitted' when it is correctly saved.
My code is going bellow.
HTML code
<form name="citizenForm" ng-submit="citizensCtrl.createCitizen(citizenForm)" class="css-form" novalidate>
<div class="form-group">
<label for="citizen_name">Nome *</label>
<input type="text" class="form-control" id="citizen_name" placeholder="Nome" ng-model="citizensCtrl.citizen.name" required>
<div class="form-group">
<label for="citizen_birthday">Nascimento *</label>
<uib-datepicker ng-model="citizensCtrl.citizen.birthday" class="well well-sm" datepicker-options="citizensCtrl.dateOptions" required></uib-datepicker>
</div>
<div class="form-group">
<label for="citizen_cell_phone">Celular *</label>
<input type="text" class="form-control" id="citizen_cell_phone" placeholder="Celular" ng-model="citizensCtrl.citizen.cell_phone" required>
</div>
<div class="form-group">
<label for="citizen_phone">Telefone *</label>
<input type="text" class="form-control" id="citizen_phone" placeholder="Telefone" ng-model="citizensCtrl.citizen.phone" required>
</div>
<hr>
<h4>Endereço</h4>
<div class="form-group">
<label for="citizen_address_district">Bairro *</label>
<select id="citizen_address_district" ng-model="citizensCtrl.citizen.address.district" class="form-control"
ng-options="district as district.name for district in citizensCtrl.districts" ng-change="citizensCtrl.getAddresses()" required>
<option value=""> Bairro</option>
</select>
</div>
<div class="form-group">
<label for="citizen_address_public_place">Rua *</label>
<input type="text" ng-model="citizensCtrl.citizen.address.public_place" id="citizen_address_public_place"
uib-typeahead="address as address.public_place for address in citizensCtrl.addresses | filter:{public_place: citizensCtrl.citizen.address.public_place} | limitTo:5"
typeahead-min-length="6" typeahead-select-on-exact="true"
typeahead-on-select="citizensCtrl.getZipCodes()"
typeahead-loading="loadingLocations"
ng-disabled="!citizensCtrl.citizen.address.district.id"
typeahead-no-results="noResults" class="form-control" required>
<i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
<div ng-show="noResults">
<i class="glyphicon glyphicon-remove"></i> Endereço não encontrado
</div>
</div>
<div class="form-group">
<label for="citizen_address_zip_code">CEP *</label>
<select id="citizen_address_zip_code" ng-model="citizensCtrl.citizen.address.zip_code"
ng-disabled="!citizensCtrl.citizen.address.public_place.id" class="form-control"
ng-options="zip_code as zip_code.number for zip_code in citizensCtrl.zip_codes" required>
<option value="">CEP</option>
</select>
</div>
<div class="form-group">
<label for="citizen_address_number">Numero *</label>
<input type="text" class="form-control" id="citizen_address_number" placeholder="Numero" ng-model="citizensCtrl.citizen.address.number" required>
</div>
<div class="form-group">
<label for="citizen_address_complement">Complemento</label>
<input type="text" class="form-control" id="citizen_address_complement" placeholder="Complemento" ng-model="citizensCtrl.citizen.address.complement">
</div>
<input type="submit" class="btn btn-primary" value="Criar" />
<input type="reset" class="btn btn-default" ng-click="citizensCtrl.defineCitizen()" value="Limpar Formulário" />
</form>
CSS code
.css-form.ng-submitted .ng-invalid{
border: 1px solid #FA787E;
}
AngularJS controller function
self.createCitizen = function(form){
if(form.$valid){
$http.post(apiUrl + endpoint, self.citizen).then(function(response){
alertsService.add('success', 'Morador criado com sucesso!');
self.defineCitizen();
}, function(error){
alertsService.add('danger', 'Oops.. Alguma coisa deu errado. Contate o administrador.');
});
}else{
alertsService.add('danger', 'Você precisa preencher todos os campos obrigatórios.');
}
};
I used form.$setPristine(); on create function
self.createCitizen = function(form){
if(form.$valid){
$http.post(apiUrl + endpoint, self.citizen).then(function(response){
alertsService.add('success', 'Morador criado com sucesso!');
form.$setPristine();
self.defineCitizen();
}, function(error){
alertsService.add('danger', 'Oops.. Alguma coisa deu errado. Contate o administrador.');
});
}else{
alertsService.add('danger', 'Você precisa preencher todos os campos obrigatórios.');
}
};
It works perfectly for me.
Thank you all