Complex HTML forms - html

This question is not as hard as it is long, it is long because I suck at explaining things, any help from moderators in reducing the length of this question or improving it's title (while keeping it's meaning) will be appreciated.
I'm designing a general application that could handle complex forms, but to do that, I need to decide how to handle the forms themselves... so let's forget about the server back-end for a while.
I've done research about this for a while now, but can't seem to find anything that isn't outdated or irrelevant.
The easiest way for me to explain this is with an example, so lets take a hypothetical "Businessman" with a "Clients Database" example:
A self employed businessman decided to keep a record for each one of his clients, where he could store all their name, phone numbers, emails, country, city and date of birth.
To do this, he uses a web-application that he can open on his mobile phone or at home on his old office computer.
But sadly, this businessman is also paranoid, and switched off all JavaScript on his computer.
The businessman might assign his secretary to add the client data, so let's call whoever is editing the form "user".
The difficult aspects of this form are supporting multiple phones and emails, and the country > city selection without JavaScript.
There are a couple of solutions, the simplest would be to first store the client and then give him a all his phone numbers, emails and country AFTER he actually exists, but in this case the client is required to have his/her country selected and at least one phone number upon storage.
Select country and city could be done by having one form with a "select country" field and a disabled "select city" without any values and a button that says "select country" or something similar... it would use the rarely used form buttons and resemble something like this:
<h2>General info</h2>
...name, surname, gender, age selection...
<h2>Country and city</h2>
<p><label>Select country: </label><select name="country">
<option value="United Kingdom">United Kingdom</option>
<option value="United States">United States</option>
<option value="France">France</option>
<option value="Germany">Germany</option>
<option value="Spain">Spain</option>
<option value="Italy">Italy</option>
<option value="Canada">Canada</option></select>
<input type="button" name="select[country]" value="Select Country" /></p>
<p>Select city: <select disabled="disabled"><option value="">No city selected<option></select> (you must first select a country)</p>
The user clicks the "Select Country" button, and the form will display all his entered data and a "cities" select field based on his chosen country
(as long as the form validates the data it outputs, and uses a unique token for the form, it should be secure)
It would also show the countries select field as disabled with his chosen country as the selected value, and a button to clear his selection, we do this to prevent the user from selecting the country, for example "United States" and then the city "New York", and later changing his choice in country and to prevent him from submitting a form with the values country="Uruguay" and city="New York".
Another approach would be to display only a single button called "Select country/city" that when clicked leads to a country selection form, that in turn leads to a city selection form, that when submitted returns the user to the form where he started. But I think the solution above this one is better.
Please correct me if there is a better way.
Then after selecting the country and city, the user of the form has to add at least one phone number to the yet to be stored "client".
(emails would be handled the same way)
This part, I haven't managed to do and would like some help with.
All that I have so far is this:
...name, surname, gender, age selection...
...country/city selection...
<p><input name="add[phone]" type="button" value="Add phone number" /></p>
clicking "Add phone number" would lead to a different page where the user can enter a phone number, it would then get added to a list of input fields:
...name, surname, gender, age selection...
...country/city selection...
<p><input name="add[phone]" type="button" value="Add phone number" /></p>
<p>
List of phones that will be added when the client is saved:<br/>
<ul>
<li>987654321<input name="phone[0]" type="hidden" value="987654321" /><button name="remove[phone][0]" value="Remove" /></li>
<li>987654322<input name="phone[1]" type="hidden" value="987654322" /><button name="remove[phone][1]" value="Remove" /></li>
</ul>
</p>
I'm pretty sure there is a better way, that I'm doing something wrong above, and I need some help.
Give sample HTML if the answer could be understood in multiple ways.
P.S. It doesn't have to be a "clients database" form, only that it should support chained selects and adding multiple variable "values" (like phones and emails in this case) for a single entry.
Edit:
Now that I think of it, the phones should be editable, so it should look like this instead:
...name, surname, gender, age selection...
...country/city selection...
<p><input name="add[phone]" type="button" value="Add phone number" /></p>
<p>
List of phones that will be added when the client is saved:<br/>
<ul>
<li><input name="phone[0]" type="text" value="987654321" /><button name="remove[phone][0]" value="Remove" /></li>
<li><input name="phone[1]" type="text" value="987654322" /><button name="remove[phone][1]" value="Remove" /></li>
</ul>
</p>
"Add Phone" leads to a form with all the same fields but they will be hidden and pre-populated with the user values, and a field to add a new Phone.
or maybe I could skip that entirely and just show the same page but with an empty phone number added... or edit all the fields on a different page?
issues also arise if you add and edit with this form.

what's so wrong with your solutions?
If you can't use javascript, you sure have to use multiple pages in order to handle dependencies between fields. That's what most frameworks call a screen-flow.
If you know which devices / browsers are used, you could try to replace the multiple pages with framesets... the target of the country select would be a initially empty frameset which will display all cities as soon as it gets the country from the first select... (do you feel what I am thinking of? :-)
but framesets are ugly and cause a lot of problems.
So my advice would be to go with a screen-flow and make sure that response times are really fast...
Update: if the problem is how to handle multiple users working on the forms...:
a session is useful to identify the user and keep track of the state of already filled out form elements
even better (more robust) is to keep the information you need (from already filled out elements and other meta data) in <input type='hidden'> fields. This way, you don't have to keep a session - the form will always submit all data to the server. But make sure that you validate all fields again in the last step - the user might have modified the request.

Related

Datalist element, possible to autofill multiple inputs?

I'm working on a datalist element to populate same fields with information about a location (Address, state, city, zip code, etc.) I noticed that Chrome can autofill multiple fields with a selection from it's pre-saved addresses that have been entered before, using an entry form one field's datalist. What I'm wondering is if it's possible for me to create options that take advantage of some browser behavior to fill multiple fields myself, or if this will need to be done programmatically. I'll post a little example snippet to try to make it more clear about what I want to do:
<input type='text' name='address' list='address-suggestions' />
<datalist id='address-suggestions'>
<option>123 Example Address Rd., New York City, NY 10001</option>
</datalist>
<input type='text' name='city' />
<input type='text' name='state' />
<input type='text' name='zip-code' />
My goal is to fill in all four fields with the option available in the datalist I'm quite confident I can do it programmatically, but given that I'm seeing Chrome do it natively, I was wondering if there was some functionality I was unaware of / had not been able to find information about elsewhere.
Yes it's possible but not all browsers behave the same.
The MDN Docs should provide some help if your using the autocomplete HTML Attribute. It should allow you better control of what gets autofilled and what doesn't.

Autofilling form does not work on all browsers

I am trying to create an autofilling form for shippment details such as name, surname, street, postal code and so on. I want the form the autofil depending on the chosen "profile" - a data which was already filled in previously to avoid re-entering data if user uses the website many times.
When filling in the form clicking on submit and afterwards going back to the order page, the autofill is not possible.
tried:
https://developers.google.com/web/updates/2015/06/checkout-faster-with-autofill
https://www.w3.org/TR/html52/sec-forms.html
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete
Raw code, without any changes:
<form class="f-form f-form--basket checkout">
<div class="f-form__col">
<div class="f-field f-field--text">
<label class="f-field__label" >
First name
</label>
<input type="text" class="f-field__control" name="firstName" placeholder="First name*" required>
</div>
</div>
<div class="f-form__col">
<div class="f-field f-field--text">
<label class="f-field__label">
Last name
</label>
<input type="text" class="f-field__control" name="lastName" placeholder="Last name*" required>
</div>
</div>
<button class="c-btn">
Pay!
</button>
</form>
You said your goal was to "autofill" the empty form with "data which was already filled in previously". That's two separate ideas that seem to be getting crossed here:
The documentation pages you link to reference a browser feature called "Autofill", which is the idea that an individual user in their own workstation's browser can fill in information about themselves (demographic information like name and email, and shipping address information), and then the browser can help them fill in forms properly.
This sort of function would work well for you, if the fields you're trying to fill in are standard demographics fields. But in order for the users to take advantage of it, it's up to to the user to update their browser's preferences to set their own "Autofill profile" (you can't do that as the web developer from HTML/JS.
The second part of what you said referenced data "they already filled in"; presumably you mean information they filled in on your site, the first time through? In order to get that idea to work, you would need to save the information the user entered, somehow. You could either save the data client-side in a cookie or other HTML5 local storage option, and use Javascript to re-fill in those values when the user visits the page again, or if the user has an account with you and is logged in, you can save that data on the back-end and generate the HTML with the default values already filled-in, or build some other API endpoint to fetch their default values via Javascript/AJAX from the front-end.

Joomla 2.5: passing parameters to contact form

I've an adhoc component to manage vehicles and if the user wants more information about a vehicle, I want to redirect him to a contact form passing the vehicle's ID as a parameter to the form, in order to get vehicle's name and other info prior to send the mail.
How can I achieve this?
Now I'm using Fox Contact Form, but I can change it if there is a better alternative.
I am not familiar with the capabilities of Fox Contact Form, but we do exactly this on several auto sites using ChronoForms. This is a 2 step process. First you must decide how you are going to package the information on the originating page.
If the more info is a link, then you will need to pass the information to the form as part of the query string. Your links would have to be formed something like this:
http://www.yoursite.com/index.php?option=com_chronoforms&view=form&year=2000&make=Ford&model=Mustang
You can add as many parameters as you would like to pass to the form.
If the more info can be turned in to a form, then you can add hidden fields to the form that include all of the data you want to pass to the contact form.
The second part of the task is to add a bit of code to the fields in the contact form so that the items auto populate in to the form. For example:
<input type="text" name="year" value="<?php JRequest::getVar('year',''); ?>">
<input type="text" name="make" value="<?php JRequest::getVar('make',''); ?>">
<input type="text" name="model" value="<?php JRequest::getVar('model',''); ?>">
This would give you input fields that the user can then edit, but you could easily make the fields read-only or hidden fields instead of text boxes.

Update one(or more) field of a member (registered on a website) using Servlets, JSPs , EJBs

I am working on a website program of a 'carhiring agency'
A user can register (done) - using Servlet & Jsp page
Login if already a member(done) - using java bean , servlet and jsp
Make a booking (done)
Delete a booking (done)
I am using netbeans IDE together with mysql(tables : cars, bookings, members) and am connecting from webpages to MYSQL via JDBC. Now i got a little stuck on this part of the task:
Update his/her account (i.e. details)
why? thought of different alternatives such as asking the user to enter username, then displaying the record with member's details , presenting checkboxes so that the user checks the fields he/she wants to change then use the normal query in servlet to update the database. However this doesnt seem to me as the best or 'nicest' option.
I would like to display the 'same' webpage as for the register with the textboxes already populated,(so if the user entered 'Maria' as name, the text box will already have Maria) so that they can be edited there and then and upon pressing submit the record for that particular member is updated. Do i have to use Session methods (.setAttribute etc) to keep the username of the member then display the information in textbox using String uname request.getParameter("username").toString(); (for example)
How would you go about doing this ? Opinions and code snippets are much appreciated
Thanks :))
Just let JSP generate the HTML accordingly that all those values are prefilled, preselected and prechecked. In the belows examples, I'll assume you've the currently logged-in user available as ${user}.
For input elements, just print the value attribute:
<input type="text" name="username" value="${fn:escapeXml(user.username)}" />
<input type="text" name="email" value="${fn:escapeXml(user.email)}" />
<input type="text" name="firstname" value="${fn:escapeXml(user.firstname)}" />
<input type="text" name="lastname" value="${fn:escapeXml(user.lastname)}" />
(the fn:escapeXml() is very important here as it prevents possible XSS attack holes)
For dropdowns, just conditionally print the selected attribute on the <option>:
<select name="country">
<c:forEach items="${data.countries}" var="country">
<option value="${country.code}" ${user.countryCode == country.code ? 'selected' : ''}>${country.name}</option>
</c:forEach>
</select>
For radiobuttons and checkboxes, just to conditionally print the checked attribute:
<c:forEach items="${data.genders}" var="gender">
<input type="radio" name="gender" value="${gender.id}" ${user.genderId == gender.id ? 'checked' : ''}" /> ${gender.description}
</c:forEach>
Collecting the submitted values should happen the same way. The only difference is that you don't need to create a new user, but just update the currently logged-in user as available by ${user}.

Auto-append items from a select list

I have a list of different items within a select multiple list and I want to auto-append to a form that a user submits.
HTML of category multiple select list:
<select name="category[]" size="4" multiple="multiple" id="group">
<option value='7'>Faculty</option>
<option value='8'>Staff</option>
<option value='6'>Students</option>
</select>
I want to do something like:
<input type="hidden" name="category[7,8]" />
This will automatically assign the submission to the appropriate selected list items from within category[], without them ever seeing it.
This is stored within a database, so I need to accomplish it this way.
I know this does not work, but this should give you an idea of what I am trying to do.
A successful multiple-select control just gets submitted as having multiple values. E.g., if you selected "Faculty" and "Staff" in your list, what gets submitted is something like:
category[]=7&category[]=8
You can replicate this (at least in Firefox, haven't tested elsewhere) with two hidden inputs:
<input name="category[]" value="7" type="hidden"/>
<input name="category[]" value="8" type="hidden"/>
I believe this could be accomplished using a Javascript library (such as jQuery) to handle the change on the Selections and append/update the items in your hidden field. You could then also use Ajax to update your database with the selection when necessary.
Your specific requirements might not allow for the above though. Some additional information would be helpful for those viewing such as what backend you're using (php, asp.net, or if it is just static html) and if you are currently using javascript (or a library) to assist you in any other tasks.
I'll try to check back on updates to see if I can be of more specific help. (Note: I think I'm too low of reputation to be able to post this as a comment at the moment so had to do an answer instead.)