Drop down list in laravel form - html

I have been working to build a laravel form and for the fields where text input is required I have successfully created. The following part works.
<fieldset>
<legend><span class="number">1</span> Personal Information</legend>
<input type="text" name="name" placeholder="Name *" value="{{old('name') }}">
<div>{{ $errors->first('name') }} </div>
<input type="text" name="email" placeholder="Email *" value="{{old('email') }}">
<div>{{ $errors->first('email') }} </div>
<input type="text" name="phone" placeholder="Phone *" value="{{old('phone') }}">
<div>{{ $errors->first('phone') }} </div>
However, I want to make a drop down list of countries (and after this two or three other drop down lists). This is the HTML part of it. How do I use a drop down list in Laravel where the selected country will appear in the email I receive after the user submits the form?
<label for="nationality">Nationality:</label>
<select id="nationality" name="nationality">
<option value="select_nationality">*</option>
<option value="india">Afghanistan</option>
<option value="india">Albania</option>
<option value="india">Algeria</option> (includes all the countries in the list)

Related

Laravel : Why i got 403 error after submit form in laravel

I submitted value of special characters in form and i got 403 error.
I stored <!DOCTYPE html> this type of values but database not accept to this type of values so how can i solve this error?
Blade file:
<form action="submit-course-detail" method="POST" accept-charset="UTF-8">
#csrf
<label>Course Name</label>
<select name="course_name" class="form-control" style="width:70%;">
<option value="">Select Course Name</option>
#foreach($course as $cou)
<option value="{{ $cou->id }}">{{ $cou->course_name }}</option>
#endforeach
</select>
<label class="mt-4">Topic Name</label>
<input class="form-control" name="topic_name" placeholder="Enter Topic Name" style="width:70%;">
<script src="https://cdn.ckeditor.com/4.19.1/full/ckeditor.js"></script>
<label class="mt-4">Description 1</label>
<textarea name="desc_one" placeholder="Write your code"></textarea>
<script>
CKEDITOR.replace( 'desc_one' );
</script>
<label class="mt-4">Description 2</label>
<textarea name="desc_two" placeholder="Write your code"></textarea>
<script>
CKEDITOR.replace( 'desc_two' );
</script>
<button type="submit" class="btn btn-success mt-3">Submit</button>
</form>
in this desc_one and desc_two is not accept character value so how to solve?

Required is not working in <select required/>

<div class="form-group">
<div class="controls">
<label class="required" asp-for="Designation"></label> <span class="danger" asp-validation-for="Designation"></span>
<select id="Designation" name="Designation" class="form-control" asp-for="Designation" required>
<option value="0" selected>Please select a Designation</option>
#foreach (var item in designation list)
{<option value="#item.DesignationName">#item.DesignationName</option>
}
</select></div>
this is my html drop down where designation list fetch the data of all employee which works fine
MY PROBLEM is that the I put required in select statement for validation and which doesn't work as it do not shows any message when field is not filled .How can I solve this
I need when No designation is selected it shows field required message on form
Try using an empty value in the first tag, since required works on empty elements. You may refer to the documentation if needed.
<div class="form-group">
<div class="controls">
<label class="required" asp-for="Designation"></label>
<span class="danger" asp-validation-for="Designation"></span>
<select id="Designation" name="Designation" class="form-control" asp-for="Designation" required>
<option value="" selected>Please select a Designation</option>
#foreach (var item in designation list)
{
<option value="#item.DesignationName">#item.DesignationName</option>
}
</select>
</div>
</div>

How can I implement Bootstrap's Datalists with Flask-SQLAlchemy SelectField

I am creating a form for my application. Currently, I want to take the user's gender, but I do not know how I can implement the field elegantly in my HTML.
I have been using Bootstrap for most of my HTML, so I want to carry that on and user their Datalists to display the various options.
Bootstrap's code for Datalists :
<label for="exampleDataList" class="form-label">Datalist example</label>
<input class="form-control" list="datalistOptions" id="exampleDataList" placeholder="Type to search...">
<datalist id="datalistOptions">
<option value="San Francisco">
<option value="New York">
<option value="Seattle">
<option value="Los Angeles">
<option value="Chicago">
</datalist>
How I have been implementing forms, such as for the StringField:
<form method="post" novalidate>
{{ form.hidden_tag() }}
<div class="form-group">
{{ form.username.label }}
{{ form.username(class_="form-control", size=32) }}
</div>
...
How can I look to implement Flask-SQLAlchemy's SelectField in a similar fashion?
Note: I not too familiar with how Bootstrap fits with Jinja; the code I have written previously for forms is not very complicated, meaning I have not had to properly understand how it works - until now.
I had the same question; but no answer. After struggling for a while, I have got it to work.
forms.py:
class fiscalYearForm(FlaskForm):
fy_timeframe = SelectField(
"Please Select Fiscal Quarter",
choices=[
('FY2022 Q4', 'FY2022 Q4'),
('FY2022 Q3', 'FY2022 Q3'),
('FY2022 Q2', 'FY2022 Q2'),
('FY2022 Q1', 'FY2022 Q1'),
],
validators=[DataRequired()],
)
html file:
<form action="" method="post">
{{ form.hidden_tag() }}
<div class="mb-3">
{{ form.fy_timeframe.label(class="form-label") }}
<input class="form-control" list="fylistOptions" placeholder="Type to search...">
<datalist id="fylistOptions">
{{form.fy_timeframe(class="form-control form-control-sm")}}
</datalist>
</div>
<div class="mb-3">
{{ form.submit(class="btn btn-primary" }}
</div>
</form>
This worked for me. Hope it helps someone.

HTML not printing the full name returned by flask

I want to know why the input filed is displaying only Varun not Varun Achar
Following is the code of my HTML page.
{%if users%}
<label >
Patient ID
</label>
<input type="text" name="PID" value={{ users[1] }}>
<label >
Patient Name:
</label>
<input type="text" name="pname" value={{ users[2] }} />
{%endif%}
Here in command prompt its printing Varun Achar but in the front HTML input field, it's printing only Varun.
Please help with this issue
You just need to wrap that value with double quotes.
{%if users%}
<label>
Patient ID
</label>
<input type="text" name="PID" value= "{{users[1]}}">
<label>
Patient Name:
</label>
<input type="text" name="pname" value="{{users[2]}}"/>
{%endif%}

Formmail returning recipient not found issue

I am trying to build a form, and I am using my providers built in formmail (which is basic formmail) I am told that it is configured to accept images as part of the formmail. When I run the form without the Enctype tag, it works it just does not send the image. Upon research I learned that you need to add the enctype="multipart/form-data" tag onto the form, it will allow the image to be sent with the form. Once I add the enctype tag, I get this error, however my recipient field is filled out and it DOES work if I do not use the enctype tag, however I can't send files. I will also note I do not have access to my providers formmail.pl.
Error: Bad/No Recipient
There was no recipient or an invalid recipient specified in the data sent to FormMail. Please make sure you have filled in the recipient form field with an e-mail address that has been configured in #recipients. More information on filling in recipient form fields and variables can be found in the README file.
FormMail V1.92 © 1995 - 2002 Matt Wright
A Free Product of Matt's Script Archive, Inc.
Below is my HTML.
<div class="container" id="indexbody">
<div class="row">
<div class="col">
<div class="content trophy">
<h3 class="h3-seo sechead">Ordering</h3>
<hr>
<form enctype="multipart/form-data" method="POST" action="http://hometeamsupply.com/cgi-bin/formmail">
<p>
<label style="margin-right: 100px">Name:
<input type="text" name="name" size=30 required>
</label>
<label>E-mail:
<input type="email" name="email_address" size=30 required>
</label>
</p>
<p>
<label>Catalog:</label>
<select name="catalog">
<optgroup label="Apparel & Accessories">
<option>Pennant Sportwear 2018</option>
<option>Alphaborder Apparel & Accessories</option>
<option>SanMar Apparel, Bags, & Caps</option>
</optgroup>
<optgroup label="Trophies, Awards & Engravables">
<option>Corporate Awards & Gifts</option>
<option>Sports Awards & Gifts</option>
<option>General Awards</option>
<option>Engravables & Gifts</option>
<option>Trophies & Accessories</option>
</optgroup>
<optgroup label="Workwear & School Jackets">
<option>GAME Workwear & School Jackets</option>
</optgroup>
<optgroup label="Uniforms and Teamwear">
<option>Badger Sports 2018</option>
<option>Augusta/Holloway/High-Five 2018</option>
<option>Alphaborder Team 365</option>
<option>Teamwork Athletic Apparel</option>
</optgroup>
</select>
</p>
<p>
<label>Order:</label><br>
<textarea name="order" placeholder="Enter Order Here" rows="4" cols="50" required></textarea>
</p>
<p>
<label>Logo Upload:</label><br>
<input type="file" name="image" accept="image/*">
</p>
<p><button>Submit</button> <button type="Reset">Reset</button></p>
<br>
<input TYPE="hidden" NAME="recipient" VALUE="donrobinson#hometeamsupply.com">
<input type="hidden" name="subject" value="HTS Online Order - E-Commerce">
<input type="hidden" name="title" value="HTS Online Order - E-Commerce">
<input type=hidden name="redirect" value="http://www.hometeamsupply.com/HTSthanks.htm">
<input type="hidden" name="return_link_url" value="http://www.hometeamsupply.com/HTSthanks.htm">
<input type="hidden" name="return_link_title" value="http://www.hometeamsupply.com/HTSthanks.htm">
<input TYPE="hidden" NAME="email" VALUE="postmaster#hometeamsupply.com">
<input type="hidden" name="background" value="">
<input type=hidden name="required" value="name,email,order">
<input type=hidden name="sort" value="order:="name,email,catalog,order,file">
<!--End private fields-->
<input TYPE="hidden" NAME="env_report" VALUE="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT"></p>
</form>
</div>
</div>
</div>
</div>