From the time a person in this country becomes a young adult, he will often find himself in a situation when he is filling out an HTML form. It could be something as simple and mundane as signing up to use his or her favorite social media app.
To use the action attribute of the form element, the form would look something like the following:
<formaction=”...”method=”post”> … </form>
In the above example, the content type is application/x-www-form-urlencoded. This content type is generally handled by a PHP file. The URL of this PHP file would be the value of the action attribute.
Let’s Look at Some Code
A fairly simple example of an HTML form would be the following:
<formid=”myform”class="pt-4"><divclass="input-group position-relative"><inputtype="text"name=”subscriber_name”class="form-control bg-white rounded-left"placeholder="Enter your name"><inputtype="email"name=”subscriber_email”class="form-control bg-white rounded-left"placeholder="Enter your email address"><buttontype="submit"class="btn btn-secondary bg-hover-primary border-hover-primary">
Above, is the HTML code of a common subscription form. Among other things, this HTML form contains two <input /> elements representing text fields. One <input /> element capture’s the user’s name and the other captures the user’s email. And there’s a submit button to process the data after the user is finished entering it into the form.
The developer may also use a <input type=”submit” value=”submit” /> instead of the <button /> element. The button element is generally used when the developer intends to do additional styling of the button.
An example of an event handler handling the submit event of the above HTML form would be the following: