HTML Buttons;
What is it?
- Buttons come in a few different shapes and sizes that can be used in HTML forms or for use with JavaScript
- There are several types of buttons (Submit, Radial, Checkbox, Combo Box, Date)
- Submit buttons are most commonly used for submitting a form. Submitting a contact form is probably the most commonly used.
- Radial buttons are good for selecting only 1 out of a few options provided in a form.
- Checkboxes allow you to check one or multiple items in a form
- ComboBoxes are great for providing a list of options (and there are additional features for selecting one or multiple items on a list)
- Date Buttons are great for collecting dates of birth or for scheduling.
Syntax:
- Submit: <input type='submit' value='submit'>
- Radial: <input type='radial' >
- Checkboxes: < input type='check' >
- ComboBoxes:< select > <option value='option 1'> Option 1 </option>
- Date: < input type='date' >
Basic Input Form Example :
<form action='transmitmydata.php' method='post' >
<input type='text' placeholder='Enter Phone Number Here' name='phone' >
<input type='button' value='Submit'>
</form>
|
What's happening in the script above?
- We've got a form with 1 text input, and 1 submit button
- The form has two additional elements "action='transmitmydata.php" and "method='post'"
- The action element is where the data is going to be sent when someone clicks the button
- The method can either be Post or Get ("post" passes the information invisibly, "Get" passes the information visibly in the browser)
- When a user clicks the button, the form has been instructed to send the data in the text box which we've named "phone" to transmitmydata.php
- transmitmydata.php will read that information and do something with it, like send an email, text message or store the information in a database.
Example Output:
transmitmydata.php:
<?php
$phone_number = $_POST(phone);
$email_subject = "Customer Phone Number";
mail("sales@mystore.com" , $email_subject , $phone_number);
?>
|
What's happening in the script above?
- The Transmitmydata.php reads the form data specifically the POST data coming from the phone field.
- The data from the phone field got passed to the PHP script which then combined it with the subject of an email
- then used the mail() function in PHP to fire off an email to sales@mystore.com
- Unlike HTML, CSS and JavaScript that all run locally (e.g. on your computer alone), PHP sits on a server
- Many common website providers like hostgator.com offer PHP out of the box so you could copy that code, save it as transmitmydata.php
- Then upload both the form and transmitmydata.php to your websiteand it should run.
See also; HTML Form
See also; HTML Buttons
See also; HTML Iframe