Form Alignment CSS - html

This is one thing that I really hate within development is forms. Below is my code and what I am trying to do is align the inputs with the labels Name: input. Is there a rule that you use to help remember when coding forms?
CSS:
#newwebsiteForm form{
padding:10px;
margin:10px 0;
width:480px;
position: relative;
}
#newwebsiteForm label{
width:240px;
display:block;
float:right;
}
#newwebsiteForm input{
width:240px;
display:block;
float:left;
}
HTML:
<section id="content">
<h1>Free Quote</h1>
<p>Please fill out the below questionnaire to receive your free web development quote</p>
<form action="" method="post" accept-charset="utf-8">
<select name="requiredOption" id="requiredOption">
<option id="pleaseselect" value="pleaseselect">Please Select Your Required Quote</option>
<option id="newwebsite" value="newwebsite">New Website</option>
<option id="websiteredevelopment" value="websiteredevelopment">Website Redevelopment</option>
<option id="other" value="other">Other</option>
</select>
</form>
<div id="newwebsiteSection">
<form action="" id="newwebsiteForm" method="get" accept-charset="utf-8">
<fieldset>
<label>Do You Require Hosting?</label><input type="radio" name="Yes" value="Yes">Yes</input><input type="radio" name="No" value="No">No</input>
<label>Do You Require A Domain?</label><input type="radio" name="Yes" value="Yes">Yes</input><input type="radio" name="No" value="No">No</input>
<label>Do You Have A Logo?</label><input type="radio" name="Yes" value="Yes">Yes</input><input type="radio" name="No" value="No">No</input>
<label>What is your Domain?</label>
<input type="url" name="domain" value="http://example.com"></input></div>
<label>Type of site Required?<label>
<select name="newwebsiteType" id="newwebsiteType">
<option value="shoppingCart">Shopping Cart</option>
<option value="CMS">Content Management System</option>
<option value="static">Static Website</option>
<option value="otherDevelopment">Other Development</option>
</select>
<label>Do You Require A Design?</label>
<input type="radio" name="Yes" value="Yes">Yes</input><input type="radio" name="No" value="No">No</input>
<label>Three Favorite colors?</label>
<input name="color1" value=""></input>
<input name="color2" value=""></input>
<input name="color3" value=""></input>
<label>What are your favorite websites?</label>
<input type="text" name="fav1" value=""></input>
<input type="text" name="fav2" value=""></input>
<input type="text" name="fav3" value=""></input>
<label>Comments?</label>
<textarea name="comments" id="comments"></textarea>
<input type="submit" name="submit" value="Send Quote Request">
</form>
</div>
<div id="websiteredevelopmentSection">
<p>Website Redevelopment</p>
</div>
<div id="otherSection">
<p>Other</p>
</div>
</section>

Just because tables are the easier option doesn't make using them right.
Here's a great article about css form design.
http://www.alistapart.com/articles/prettyaccessibleforms
The author suggests storing each label/input element in an ordered list element keeping them grouped.
I've just used this to implement a bunch of forms for various mini sites and it worked a treat!
You can align the label next to the input or above just by changing the ol li label element's display property from display:inline-block to display:block respectively.
Getting the text to align next to a radio button or checkbox can be a bit tricky but is possible by adding and styling a span element.
BEST OF ALL IT'S CROSS BROWSER COMPATIBLE!
Hope that helps.

This is probably related to the question: <div> usage correctly? Can't get the columns to line up: You can also check my comments there for some reference when dealing with semantically-correct forms.
The approach you will need to be in habit of is always structure your markup correctly first before jumping to any CSS (or styling).
A <form> is composed of the following:
The <form> itself.
The <fieldset>: acts a the container of the different sections of your <form>
The <legend>: acts as the heading of the <fieldset>
The <input />: for fields, checkboxes, radio buttons, and submit button
The <button>: an alternative for <input type="submit">, which can wrap something
inside of it.
The <select>: a list of values inside a drop-down menu.
The <label>: from the name itself, the label of the <input />, <button> and <select>
To illustrate, you can check this example:
<form>
<fieldset>
<legend>Form Heading: </legend>
<fieldset>
<legend>Group 1 Heading: </legend>
<label for="input-id">Input Label: </label>
<input id="input-id" />
</fieldset>
<fieldset>
<legend>Group 2 Heading: </legend>
<label for="select-id">Select Label: </label>
<select id="select-id">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
</fieldset>
<input type="submit" value="Submit" />
</fieldset>
</form>
With the exception of radio (<input type="radio" />) and checkboxes (<input type="checkbox" />), where the <label> should come after the <input />

You have to use the label element as follows to correctly align them:
<FORM action="http://somesite.com/prog/adduser" method="post">
<P>
<LABEL for="firstname">First name: </LABEL>
<INPUT type="text" id="firstname"><BR>
<LABEL for="lastname">Last name: </LABEL>
<INPUT type="text" id="lastname"><BR>
<LABEL for="email">email: </LABEL>
<INPUT type="text" id="email"><BR>
<INPUT type="radio" name="sex" value="Male"> Male<BR>
<INPUT type="radio" name="sex" value="Female"> Female<BR>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</P>

I wrap each input/label pair in a <div>. This helps a lot with styling.
<div class="form-item">
<label for="first_name">First Name</label>
<input type="text" name="first_name" id="first_name" />
</div>

Related

Jquery serializeArray not getting all fields

I have this HTML:
<div id="broker_referral_block" style="display: none;">
<label for="">* How did your broker/agent introduce you to the project?</label><br>
<input type="radio" name="referral2" value="Site Visit" class="referral2"> Site Visit
<br>
<input type="radio" name="referral2" value="Conversation through social media" class="referral2"> Conversation through social media
<br>
<input type="radio" name="referral2" value="Referrals" class="referral2"> Referrals
<br>
<input type="radio" name="referral2" value="Phone Calls" class="referral2"> Phone Calls
<br>
<input type="radio" name="referral2" value="Developer" class="referral2"> Developer
<br>
<input type="radio" name="referral2" value="Other" class="referral2"> Other
</div>
I don't know why it's not included when I try to serializeArray var test = jQuery(this).serializeArray(); I don't see anything wrong. I know the display:none; is not an issue because this field:
<div id="broker_referral_block_other_field" style="display: none;">
<input type="text" class="form-control referral2other" name="referral2other" id="referral2other">
</div>
Gets read, just without value (which is what I want). I also don't understand why everything in this block gets read:
<div id="existing_loans_block" style="display: none;">
<label for="">* Loan</label>
<input type="text" class="form-control existing_loans_detail" name="loan" id="loan">
<label for="">* Amount</label>
<input type="text" class="form-control existing_loans_detail" name="loan_amount" id="loan_amount">
<label for="">* Monthly Amoritization</label>
<input type="text" class="form-control existing_loans_detail" name="loan_amort" id="loan_amort">
<label for="">* Term</label>
<input type="text" class="form-control existing_loans_detail" name="loan_term" id="loan_term">
<label for="">* Status</label>
<!-- This bit does not get included too -->
<select name="loan_status" id="loan_status" class="form-control existing_loans_detail">
<option value="" selected disabled hidden>Select loan status...</option>
<option value="Active">Active</option>
<option value="Updated">Updated</option>
</select>
</div>
Except for loan_status. All of them are properly wrapped in a form tag. This is my jquery:
jQuery("#hbcq_form").submit(function(e){
e.preventDefault();
var test = jQuery(this).serializeArray();
...
I did a console.log(test) and that's when I found out that referral2 and loan_status is not being included in the serialization. I also double checked, there is no name conflicts for these.
jQuery serialize hidden (display:none) form elemens does not work. Workaround?
check this out you can find help full answer

HTML search option with filters that link to external website

I'm required to use only HTML to create a web form in which the search result will link me to the external website's search results. There are search options with filters that I have included and when I enter the input and select the filters, it links me to the external website but it does not filter out the search from my own web form, meaning that it would treat any search as a normal search without the filters for 'month', '6months' and 'year' option.
https://www.worldscientific.com/search/advanced - The website that I am supposed to link the search result from my web form to.
HTML Code:
<html>
<style>
*{
box-sizing: border-box;
}
#border1 {
width: 1000px;
height: 500px;
padding: 15px;
border: 2px;
}
</style>
<h2>Part 3 - World Science</h2>
<form id="worldscience_search-form"
action="https://www.worldscientific.com/action/doSearch?field1=AllField&text1=text1&publication=&Ppub=&AfterMonth=&AfterYear=&BeforeMonth=&BeforeYear=&earlycite=on" method="get" target="_blank" class="jcf-select" autocomplete="off">
<div id="border1">
<div style = "float:left; width:20%">
<select id="textArea2" name="field1" style = "height:40px; width:120px;">
<option value="AllField">Anywhere</option>
<option value="Title">Title</option>
<option value="Contrib">Author</option>
<option value="Keyword">Keywords</option>
<option value="Abstract">Abstract</option>
</select>
<br><br><br>
<label for="publication">Published in</label> <br><br><br>
<label>Publication Date</label>
<input type="hidden" value="AfterYear">
<input type="hidden" value="BeforeYear">
<br>
</div>
<div style = "float:left; width:20%">
<input type="text" placeholder="Enter Search term" name="text1" style = "width: 500px; height:40px"><br><br>
<input type="text" name="publication" placeholder="e.g. Journal of Theoretical Biology" style = "width:500px; height :40px">
<br><br><br>
<input type="radio" name="Ppub" value="" checked="checked">
<label>All dates</label>
<br><br><br>
<input type="radio" name="Ppub" value="">
<label>Last</label>
<br><br><br>
<input type="radio" name="Ppub" value="">Custom Range
</div>
<div style = "float:left; width:50%">
<br><br><br><br><br><br><br><br><br><br>
<select id="Ppub" value="" style = "height:40px; width:120px;">
<option value="">Select</option>
<option value="20181218-20190118">month</option>
<option value="20180718-20190118">6 months</option>
<option value="20180118-20190118">year</option></select><br><br>
<input type="submit" value="Search" />
</div>
</form>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br>
</html>
I don't think that I should have coded the values in the option value. How am I supposed to filter out without coding in the dates?
You have to use hidden inputs: (I only show start of the form)
<form id="worldscience_search-form" action="https://www.worldscientific.com/action/doSearch" method="get" target="_blank" class="jcf-select" autocomplete="off">
<input type="hidden" name="field1" value="AllField">
<input type="hidden" name="text1" value="text1">
<input type="hidden" name="publication" value="">
<input type="hidden" name="Ppub" value="">
<input type="hidden" name="AfterMonth" value="">
<input type="hidden" name="AfterYear" value="">
<input type="hidden" name="BeforeMonth" value="">
<input type="hidden" name="BeforeYear" value="">
<input type="hidden" name="earlycite" value="on">

HTML5 only - 'Required' attribute on checkbox input preventing form from being resubmitted after validation fail

Looking for answers for HTML5 ONLY, no JS solutions please!
I'm only just beginning to code so I don't really know what to google to get the answer to this - I've already done a few good hours trying to figure it out in HTML5 only, but what I've found has all involved javascript, or didn't fix my problem. The question is:
Is there a way in HTML5 to reset the validation value once a form has been submitted once, and failed to submit/got rejected because of a missing value on a 'required' attribute? I want to make resubmission possible after someone checks the required box if they left it unchecked before, without refreshing the page.
The form in question is below, sorry for the shitpost aspects;
<html>
<head>
<h1>Register</h1>
<img src="http://elohell.net/public/comments/small/fb174f37e857128b2b5bdbf0d1c419dc.png" max height="100px" max width="100px">
</head>
<body>
<form method="link" action="https://youtu.be/eBRwu63-qfA">
<p>
<h2>Name</h2>
</p>
<label for="first">First:</label>
<input type="text" id="first" required oninvalid="this.setCustomValidity('Feed It Blood')" oninput="setCustomValidity('')">
<label for "last">Last:</label>
<input type="text" id="last" required oninvalid="this.setCustomValidity('Give More')" oninput="setCustomValidity('')">
<p></p>
<!--gender id-->
<p>
<h2>Gender</h2>
</p>
<label for="CM">Cis Man</label>
<input type="radio" id="CM" name="GS1">
<p></p>
<label for="TM">Trans Man</label>
<input type="radio" id="TM" name="GS1">
<p></p>
<label for="CF">Cis Woman</label>
<input type="radio" id="CW" name="GS1">
<p></p>
<label for="TF">Trans Woman</label>
<input type="radio" id="TW" name="GS1">
<p></p>
<label for="NBGF">Nonbinary/Genderfluid</label>
<input type="radio" id="NBGF" name="GS1">
<p></p>
<label for="AG">Agender</label>
<input type="radio" id="AG" name="GS1">
<p></p>
<label for="OTHER">Other</label>
<input type="text" name="OTHER" name="GS1">
<!--Email Password-->
<p>
<h2>Login Details</h2>
</p>
<label for="email">Email:</label>
<input type="email" name="email" required oninvalid="this.setCustomValidity('We Will Meet Soon')" oninput="setCustomValidity('')">
<label for="password">Password:</label>
<input type="password" name="password" minlength="5" maxlength="10" required oninvalid="this.setCustomValidity('Seal Your Fate')" oninput="setCustomValidity('')">
<!--Bday-->
<p>
<h2>Birthday</h2>
</p>
<label for="bday1">Which Month</label>
<select name="bday1">
<option></option>
<option>Jealousy</option>
<option>Federal Agent</option>
<option>Hell</option>
<option>April</option>
<option>Any Of The Rest</option>
</select>
<label for="bday2">The Day</label>
<select id="bday2">
<option></option>
<option>1</option>
<option>0</option>
<option>Void</option>
</select>
<label for="bday3">The Year Of THE Birth Crime</label>
<select id="bday3">
<option></option>
<option>X</option>
<option>666</option>
<option>Eternal</option>
</select>
<!--Agree&Submit-->
<p></p>
<label for="satan">I agree I agree I Agree I Agree I AGREE I AGREE I AGREE I AGREE I AGREE I AGREE</label>
<input type="checkbox" id="satan" required oninvalid="this.setCustomValidity('IT WILL BE DONE')" oninput="setCustomValidity('')" updateon="form.submit()">
<p></p>
<input type="submit" name="submitButton" value="COMPLETE">
</form>
</body>
</html>
The SPECIFIC part I'm having trouble with is this bit right here:
<!--Agree&Submit-->
<p></p>
<label for="satan">I agree I agree I Agree I Agree I AGREE I AGREE I AGREE I AGREE I AGREE I AGREE</label>
<input type="checkbox" id="satan" required oninvalid="this.setCustomValidity('IT WILL BE DONE')" oninput="setCustomValidity('')" updateon="form.submit()">
<p></p>
<input type="submit" name="submitButton" value="COMPLETE">
I'm not sure if there's something inside the rest of the form that's keeping this one part in particular from not working - the others all act as they're supposed to. If one is blank, it pops up with the custom warnings I set up, and after I fill it out, it doesn't cause me any issue anymore. The checkbox is the only one that has the persistent message popping up with the refusal to submit it again. If I check it WITHOUT submitting the form first, everything acts as it was supposed to when I do submit it.
I appreciate your help!
You have to change the oninput to onchange for input tags like this:
<html>
<head>
<h1>Register</h1>
<img src="http://elohell.net/public/comments/small/fb174f37e857128b2b5bdbf0d1c419dc.png" max height="100px" max width="100px">
</head>
<body>
<form method="link" action="https://youtu.be/eBRwu63-qfA">
<p>
<h2>Name</h2>
</p>
<label for="first">First:</label>
<input type="text" id="first" required oninvalid="this.setCustomValidity('Feed It Blood')" oninput="setCustomValidity('')">
<label for "last">Last:</label>
<input type="text" id="last" required oninvalid="this.setCustomValidity('Give More')" oninput="setCustomValidity('')">
<p></p>
<!--gender id-->
<p>
<h2>Gender</h2>
</p>
<label for="CM">Cis Man</label>
<input type="radio" id="CM" name="GS1">
<p></p>
<label for="TM">Trans Man</label>
<input type="radio" id="TM" name="GS1">
<p></p>
<label for="CF">Cis Woman</label>
<input type="radio" id="CW" name="GS1">
<p></p>
<label for="TF">Trans Woman</label>
<input type="radio" id="TW" name="GS1">
<p></p>
<label for="NBGF">Nonbinary/Genderfluid</label>
<input type="radio" id="NBGF" name="GS1">
<p></p>
<label for="AG">Agender</label>
<input type="radio" id="AG" name="GS1">
<p></p>
<label for="OTHER">Other</label>
<input type="text" name="OTHER" name="GS1">
<!--Email Password-->
<p>
<h2>Login Details</h2>
</p>
<label for="email">Email:</label>
<input type="email" name="email" required oninvalid="this.setCustomValidity('We Will Meet Soon')" oninput="setCustomValidity('')">
<label for="password">Password:</label>
<input type="password" name="password" minlength="5" maxlength="10" required oninvalid="this.setCustomValidity('Seal Your Fate')" oninput="setCustomValidity('')">
<!--Bday-->
<p>
<h2>Birthday</h2>
</p>
<label for="bday1">Which Month</label>
<select name="bday1">
<option></option>
<option>Jealousy</option>
<option>Federal Agent</option>
<option>Hell</option>
<option>April</option>
<option>Any Of The Rest</option>
</select>
<label for="bday2">The Day</label>
<select id="bday2">
<option></option>
<option>1</option>
<option>0</option>
<option>Void</option>
</select>
<label for="bday3">The Year Of THE Birth Crime</label>
<select id="bday3">
<option></option>
<option>X</option>
<option>666</option>
<option>Eternal</option>
</select>
<!--Agree&Submit-->
<p></p>
<label for="satan">I agree I agree I Agree I Agree I AGREE I AGREE I AGREE I AGREE I AGREE I AGREE</label>
<input type="checkbox" id="satan" required oninvalid="this.setCustomValidity('IT WILL BE DONE')"
onchange="setCustomValidity('')"
updateon="form.submit()">
<p></p>
<input type="submit" name="submitButton" value="COMPLETE">
</form>
</body>
</html>

HTML form Radio button positioning

My question is pretty basic. its about the placement of my radio button
The buttons are slightly below its adjacent text. how to position it exactly in front of its text
Click at the link of sign up form as it provides the image of my problem
sign up form
see this form the radio buttons are exactly before the text
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form >
<label>Name</label>
<input type="text">
<br>
<label>Email</label>
<input type="email" name="">
<br>
<label>Date</label>
<input type="date" name="">
<br>
<label>Password</label>
<input type="password" name="">
<br>
<label>Color</label>
<input type="color" name="">
<br>
<label>Select Any One</label>
<input type="checkbox" name="">Travel
<input type="checkbox" name="">Food
<input type="checkbox" name="">Hotel
<br>
<label>Select Gender</label>
<input type="radio" name="gender">Male
<input type="radio" name="gender">FeMale
<br>
<select>
<option>Select Box</option>
</select>
<br>
<textarea rows="4" cols="50"></textarea>
</form>
</body>
</html>
Removing width:100% from the following code solved the problem in your jsfiddle
*{
margin:0px auto;
}
Its because that style was applicable for all the elements the text and radio button was misplaced

How to reset multiple forms at once with one button

Okay guys, im starting to learn HTML so im a newbie at the moment. I wrote this code to practice my input types (such as password, email, text etc). I would like to know how I can reset the whole form with one button. E.g.:
<input type="reset" value="reset">
The above code should be able to reset the whole form.
In my code, I have multiple forms and fieldsets:
<! DOCTYPE HTML>
<html>
<head>
<title>Tutorial 5 </title>
</head>
<body>
<form>
<fieldset>
<legend>Personal Details</legend>
<p><label for="name">First name:</label>
<input id="name" name="name" type="text" /></p>
<p><label for="surname">Surname:</label>
<input id="surname" name="surname" type="text" /></p>
<p><label for="dob">Date of Birth:</label>
<input id="dob" name="dob" type="text" size="5" /></p>
<p><label for="email">E-Mail address: </label>
<input id="email" name="email" type="email" /></p>
<p><label for="address">Address:</label>
<textarea id="address" name="address" type="text" rows="5" cols="30"></textarea> </p>
<p><label for="postcode">Postcode:</label>
<input name="postcode" id="postcode" type="text" size="5"></input> </p>
</fieldset>
</form>
<form>
<fieldset>
<legend> Password and PIN </legend>
<p><label for="password"> Password </label>
<input id="password" name="password" type="password"></input> </p>
<p><label for="passwordRetype">Retype Password</label>
<input id="passwordRetype" name="passwordRetype" type="password"></input> </p>
<p><label for="memorableQuestion"> Memorable question</label>
<select id="memorableQuestion" name="memorableQuestion">
<option value="ChildhoodFriend"> Who was your childhood friend? </option>
<option value="Street"> Whats the street you grew up in? </option>
<option value="Food"> Whats your favorite food? </option>
</select> </p>
<p><label name="answerToQ"> Answer to memorable question: </label>
<input id="answerToQ" name="answerToMemorableQuestion" type="text"</input> </p>
</fieldset>
</form>
<form>
<fieldset>
<legend>Feedback</legend>
<p><label for="radio"> Where did you hear about us mostly?</label>
<p id="radio">
<input type="radio" name="feedback" value="social_media">Social Media<br>
<input type="radio" name="feedback" value="advertisement">Advertisement<br>
<input type="radio" name="feedback" value="Radio_ad">Radio Advertisement<br>
</p></p>
<p><label for="rate">Rate out service out of 10: </label>
<input id="rate" name="rate" type="text" size="2" /></p>
</fieldset>
</form>
</body>
</html>
As well as that, when I output it, I would like the text field to be aligned properly. (e.g. the textfields are all under each other and they all start at the same point... if you know what I mean.. is it possible to achieve this through float?)
After trying every method possible, I found this to be the simplest:
window.open(document.URL,'_self');
Typically you would use a single form to capture input with the submit / reset actions within it.
This is because the FORM element groups together the values within them in order to post back to the server or action of the form.
Therefore unless you expect the user to interact with the forms independently of each other then it makes little sense to split the form up. By combining into a single form the reset button will work.
For presentation purposes you should be using something like DIV elements or whatever makes sense for the layout you are trying to create.