sir_thursday
sir_thursday

Reputation: 5419

Implementing custom made HTML forms

This title is kind of vague so let me explain it first. I'm developing an application that is very "custom-control" heavy. I have to create lots of custom drop-down selection menus and visual controls instead of a normal <form> with inputs, buttons, etc.

Naturally, the problem is passing data with these custom-made <div> controls. Is the best way to go about doing this to have hidden input elements that populate and submit their values when these custom controls are used?

Hopefully this question won't be closed for being too "open-ended" or "opinion-based." All I am wondering is what the industry standard/common practice is.

Upvotes: 1

Views: 31

Answers (2)

hyphnKnight
hyphnKnight

Reputation: 303

Unfortunately due to the fundamental functionality of forms you must use the traditional input tags in order for submit form to actually work. There are two easy answers to this problem.

  1. You use the traditional inputs but hide them from view and write to their .value property using javascript when the user makes a change. That way the form is actually sending a series of input values.
  2. The other way to handle this depends on how you are planning on using the data. If your are sending some variables using GET to a php document to be used for some purpose then simply have your own custom form election elements set javascript variables then combine those variables into a URL then simply redirect them to that URL on submit or use an AJAX request.

To conclude, unless you absolutely have to you create your own inputs, you should not because they are specifically designed to deal with a lot of different situations (such as backwards compatibility and disability compensation).

Upvotes: 0

T0xicCode
T0xicCode

Reputation: 4951

The best way is to style the default controls to match whatever look you want. Browsers and user-agents parse form elements in a certain way, which makes your sites accessible. Using custom controls bypasses all of the considerations that have been implemented to deal with text-to-speech users, color-blind people, etc.

Upvotes: 1

Related Questions