What You Should Know about Forms in PHP for Developers - Coding Cyber

What You Should Know about Forms in PHP for Developers

As a Developer, you should work with Forms on a daily basis with every project. Here in this series of articles (YouTube Video Series), you are going to learn all the things that you should know about PHP Forms. I’ve covered most of the things that are necessary for working with forms in PHP. Even if you are a beginner or intermediate programmer/developer, you will find at least a few important concepts that you should know in this series.

Code blocks that are required for working with Forms in PHP

As you already know, you need a basic HTML skeleton for Creating any HTML or PHP pages. And you have to add the HTML head section and body section. Inside the body section, you need to add the form.

Now we are going to discuss about the form and the mandatory things in form, before going to work with them in PHP.

Form Tags

You need for opening tag and closing tag. For form opening tag, you need to add method attribute and in method attribute, you can pass the method types. You can use either the POST method or the GET method.

GET & POST Method

With the GET method, submitted form data will be passed in the URL. Anyone can see this data after submitting the form.

With the POST method, submitted form data won’t be visible to the end-user. For all the forms, we will use the POST method.

Form Input Fields

Within the forms, you can add any type of input field from the available input fields. But for all the input fields you need to pass the name attribute, otherwise, you won’t be able to access these values after submitting the form.

For radio buttons and select lists, you should add value attribute for passing the value with a selection of the radio buttons or selection of drop-down list. This value will be passed after submitting the form.

HTML5 Validations

For adding HTML5 Validations, you can add the HTML5 Validation attributes like required, min & max. And for email validation, you can use the input type as email.

These HTML5 Validations not secure, you will understand why it’s not a secure option to depend on these HTML5 Validations while adding PHP Form Validations.

Anyone with a little bit of coding knowledge can remove/disable the HTML5 Validations. That’s why it’s not recommended to depend only on HTML5 Validations.

Placeholder Text

For input fields, we need to add a placeholder text by using the placeholder attribute. By seeing the placeholder text user will understand what kind of information to submit with the input fields.

Default Selection for Input Field, Radio Button, Select List

To select an input field by default, you have to use these attributes. But for every input field, these attributes will be different. Let’s get to know about these attributes.

Autofocus for input field

After loading the form page in the browser, any input type text field can be selected by adding an autofocus attribute. In the form that I’m using, I’ve selected the first name input field.

Checked for Radio Button

And for selecting radio buttons, these radio buttons can be selected by passing checked attribute to the radio button you wanted to select by default, after loading the form page in the browser.

Selected for Select List

One of the options from the select list will be selected, for selecting option by default you have to pass selected attribute to the select option tag.

Default Select List Option

For Select dropdown, the default option should be passed as an empty value attribute, otherwise, you won’t be able to add the Form Validations for the select dropdown list. Because without passing an empty value attribute, PHP will consider the text in-between option tags as a value.

This is explained clearly in my YouTube video series about PHP Forms for Developers.

Submitting the Form

And one last thing, that you should check in our forms is the submit button. Without this submit button you won’t be able to submit the form.

Complete Code of HTML Form

Here is the complete code of the HTML form that is discussed in this article and also in the video.


Before start working on the forms, you should understand about all the input fields and the attributes that make up the form. Then only you can proceed with the next steps that are adding PHP Form Validations and displaying Success & Error Messages in PHP.

If you have any questions, feel free to ask in the comments section here or in the YouTube Comments Section.

https://codingcyber org/you-should-know-about-forms-php-developers-8817/
Vivek Vengala

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: