PHP Form Fields

Last Updated: July 31, 2021

You can use the following HTML form fields or form elements.

  1. Text Box Input.
  2. Password Input.
  3. Text Area.
  4. Select Drop Down.
  5. Check Box.
  6. Radio Input.
  7. File Input.
  8. Submit Button.

Text Box Input

This is the most common input tag in HTML form where user can type text inputs and send to the server.

<input  type="text" name="number" >

Password Input

Password can be entered in this form element so that others can not see the text when you type it

<input  type="password" name="password" >

Text Area Input

You can use this HTML form element to enter a large amount of text or paragraphs.

<textarea cols="70" rows="10"  name="text"></textarea>

Set the values for cols and rows attributes

Select Drop Down

Select one item from the several values

<select name="type">
      <option value="text" > Text</option>
      <option value="code" selected > Code</option>
</select>

Checkbox

The checkbox is shown as a square box that is ticked (checked) when activated.

You can use Checkbox to select one or more options of a limited number of choices.

<input type="checkbox" name="field name" value="Initial value">

If you want to select the checkbox based on the value coming from the $_POST or database record.

<input type="checkbox" name="is_selected"  value="yes" <?php echo ($dbvalue['is_selected']==1 ? 'checked' : '');?>>

Radio Input

You can have single radio button or radio button group

You can select only one button in a radio button group

<input type="radio" name="gender" value="male">

File Input

Users can upload files to the server using this HTML input field.

<input type="file" name="pic">

This will show the browse button where the user can select the file.

Submit Button

The submit button defines a button for submitting the form data to a form-handler.

<input type="submit" value="Save">