Can't validate inputs with "required" attribute - html

I have an HTML form, which consists of few divs, and there are label and input inside every div.
So for name and email inputs I want to add "required" property. But when I set it and then submit the form, I instantly start running the form action, even if my inputs were empty. So that's first time I face with such a trouble. It's also the first time when I put divs inside the form, but it seems like it should work anyway.
So you can see my code below:
<section>
<form id="feedback_form" method="POST" action="{% url 'feedback' %}">
<div class="field half first">
<label for="name">Name*</label>
<input type="text" name="name" id="name" required/>
</div>
<div class="field half">
<label for="email">Email*</label>
<input type="email" name="email" id="email" required/>
</div>
<div class="field">
<label for="message">Message</label>
<textarea name="message" id="message" rows="5"></textarea>
</div>
<button class="button submit" type="submit">Send</button>
</form>
</section>

So I solved this. It was an issue with some implicit javascript code on page (I usually work with backend, so haven't made this page by myself before).
So in .js file I found such part of script which disallowed submitting form in a standard way.
$('form').on('click', '.submit', function(event) {
event.stopPropagation();
event.preventDefault();
$(this).parents('form').submit();
});
So my advice: if you work with code written by others, do some more research and check files few times if you can't solve some implicit tasks.

Related

My form doesn’t show info when someone submits, for example I’ll receive the name, email, message but it’ll be blank

I’m using the FormSubmit API.
When a person fills out the form and submits it, whatever they have filled out doesn’t show and I just receive an empty form.
<section id="form-section" class="fade-contact">
<h2 id="form-title" class="fade-contact">Get in touch</h2>
<form action="https://formsubmit.co/8421d4ce6448fbeda493e2c8ce639a8e" method="POST" id="form">
<!-- <input type="hidden" name="_captcha" value="false"> -->
<!-- <input type="hidden" name="_autoresponse" value="Thank you for getting in touch!"> -->
<div class="name-email fade-contact">
<input type="text" name="name" placeholder="YOUR NAME" id="form-name" required>
<input type="email" name="email" placeholder="YOUR EMAIL" id="form-email" required>
</div>
<input type="text" name="textarea" placeholder="YOUR MESSAGE" id="form-message" class="fade-contact" required>
<button type="submit" class="btn submit-btn fade-contact">submit</button>
</form>
</section>
I corrected the name attribute to not use 2 of the same values but still it doesn’t work!
Here is an image of the formsubmitAPI website instructions
screenshot of formsubmitAPI guide
btw I hosted with netlify just incase that helps
I FIXED IT!!!!!!!
Turns out I had some JavaScript to clear the input values after submission and that was somehow affecting the form. I guess the input values were clearing before the form was submitting hence I was getting blank emails.
I just commented it out for now and will look into it later.
But…..I fixed it!! I’m so happy!
Thank you to everyone that helped

Why does my Netlify html form work, but not redirect to a confirmation page?

I'm working on a Hugo based website, that I am deploying with Netlify. I would like to include a form using Netlify's form support (docs).
My form looks like this:
<form id="contact-form" name="contact-form" data-netlify="true" method="post" role="form" action="{{ .URL }}formsuccess">
<div class="form-group">
<input type="text" placeholder="Name" class="form-control" name="name" id="name" required>
</div>
<div class="form-group">
<input type="email" placeholder="Email" class="form-control" name="email" id="email" required>
</div>
<div class="form-group">
<input type="text" placeholder="Subject" class="form-control" name="subject" id="subject">
</div>
<div class="form-group">
<textarea rows="6" placeholder="Message" class="form-control" name="message" id="message" required></textarea>
</div>
<div id="cf-submit">
<button type="submit" id="contact-submit" class="btn btn-transparent">Submit</button>
</div>
</form>
Now, this form does work. But Netlify says that you can specify the action attribute to create a link for the submit button. This is the part that I can't get to work: I stay on the form page, and can click submit infinitely (submitting the form again and again).
I have entered the path of my action attribute in a simple anchor, and there it does work.
I have also tried without the action attribute. According to the docs, this should link to a generic confirmation page, but this doesn't work for me either.
How can I redirect my users to a confirmation page after submitting?
The path must be relative to the site root, starting with a /.
Make sure the code in your static site generator is resolving to the above rule.
action="{{ .URL }}formsuccess"
needs to look similar to:
action="/path/to/formsuccess"
With the help of Netlify's support team I figured out the problem.
The action path needs to be an actual path. In my case, it needs to be in the site's public directory. I was trying to make it work with a URL with a suffix (example.com/en/pathname) or with a partial html (like many Hugo templates use). This is not possible.
When you have put in an action path, you can not use Netlify's default one anymore, because:
(Netlify's) "system stores your action path in our database and will
continue to use it until you override it with another action path."

Form valdiation email using button with link

I am trying to do something very simple using html, however I don't find an easy way to solve this, without onclick javascript events.
My code is like this:
<div class="email">
<input type="email" placeholder="Email">
</div>
<a href="validation.html">
<button class="subscription-button">Keep Me Posted!</button>
</a>
This is fairly simple.
Without the href="validation.html tag, I get an automated form validation,
notifying when '#' is missing and such.
However, when adding the link to the page, this validation is not checked, and it goes on to the next page.
How can I make it check the constraints without needing to write JS for that?
I tried this:
<form action=./validation.html>
<div class="email">
<input type="email" placeholder="Email">
</div>
<input type="submit" value="Keep Me Posted!" />
</form>
But the same result
Try using the form instead of link with a required attribute prevent empty data to auto validate the email type
<form action="validation.html">
<div class="email">
<input type="email" placeholder="Email" required>
</div>
<button type="submit" class="subscription-button">Keep Me Posted!</button>
</form>
I removed the slash from next to validation.html.
Try this:
<form action="validation.html">
<div class="email">
<input type="email" placeholder="Email" required>
</div>
<button type="submit" class="subscription-button">Keep Me Posted!</button>
</form>

How to prevent form elements from pre-populating in Chrome

I am building a Bootstrap form and the email and password form elements show with pre-populated data from some other or some earlier form login on a different site. The Chrome browser is auto-populating the form elements.
Is there an HTML attribute of method in Bootstrap to force these form elements to null or empty on page load?
2015-10-29 -- here's the markup:
<form autocomplete="off" method="post" role="form">
<div class="form-group">
<input name="formSubmitted" type="hidden" value="1">
</div>
<div class="form-group">
<label for="username">Username</label>
<input autocomplete="off" autofocus="autofocus" class="form-control" id="username" name="username" required type="text">
</div>
<div class="form-group">
<label for="password">Password</label>
<input autocomplete="off" class="form-control" id="password" name="password" required type="password">
</div>
<button class="btn btn-default" type="submit">Login</button>
</form>
Use autocomplete="new-password"
Works a charm!
Use the autocomplete="off" attribute on the <form> or <input>.
from MDN:
autocomplete
This attribute indicates whether the value of the control can be
automatically completed by the browser.
off The user must explicitly enter a value into this field for every use, or the document provides its own auto-completion method;
the browser does not automatically complete the entry.
on The browser is allowed to automatically complete the value based on values that the user has entered during previous uses...
Also from MDN, see: How to Turn Off Form Autocompletion
Also see:
Chrome Browser Ignoring AutoComplete=Off
"AutoComplete=Off" not working on Google Chrome Browser
autocomplete ='off' is not working when the input type is password and make the input field above it to enable autocomplete

How do I get my submit button to work?

I am no expert in coding. As a matter of a fact this is my first true project in CSS. I created the page in Adobe Edge Reflow and exported CSS to dreamweaver. The problem I am running into is that I can't get my form to actually work. I want the form to send directly to my e-mail, in no specific format. Can anyone help me out?
<form method="post" novalidate>
<label id="formgroup">
<p id="text1">
Name*
</p>
<input id="textinput" type="text" value=" Your Name"></input>
</label>
<label id="formgroup1">
<p id="text2">
Company Name
</p>
<input id="textinput1" type="text" value=" Company Name"></input>
</label>
<label id="formgroup2">
<p id="text3">
Email*
</p>
<input id="textinput2" type="text" value=" email"></input>
</label>
<label id="formgroup3">
<p id="text4">
Message*
</p>
<input id="textinput3" type="text" value=" Your message"></input>
</label>
<input id="submit" type="submit" value="Send Message"></input>
<input type="hidden" name="recipient" value="xxx#gmail.com"> </form>
Your HTML markup seems fine for a simple form aimed to post the contents of a range of fields.
However, the HTML code (along with any CSS) will only enable you to determine the presentation/style of the form (i.e. how it looks).
Regarding the functionality of the application actually triggering an email with the form contents to an email address, this will require more code in a 'server-side' language such as PHP (HTML and CSS being 'client-side' languages).
Here is a good article that provides a tutorial on the subject: http://www.html-form-guide.com/php-form/php-form-tutorial.html
Your HTML markup is actually missing something, the "action" property, i.e.
Before:
<form method="post" novalidate>
After:
<form method="post" novalidate action="send-email.php">
As you might have guessed from looking at the above, this "action" property specifies the PHP script/file that triggers the email. And of course it is this file that you are currently missing.
Hope this helps.