Home >Backend Development >PHP Problem >What are the commonly used attributes in php forms?

What are the commonly used attributes in php forms?

青灯夜游
青灯夜游Original
2019-10-11 17:41:394029browse

In program development, it is essential to use the form form. In the past, it was only used briefly in front-end development, and its properties were not well understood. Recently, in the back-end learning, I have been exposed to its properties. Now record them. One or two. The following article will introduce to you 5 properties commonly used in PHP forms.

What are the commonly used attributes in php forms?

action

action specifies the destination for sending form data when submitting a form, that is, where the data is sent, such as action ="login.php".

method

method specifies the sending method, commonly used are get and post. When it comes to user privacy, the post method is usually used for security reasons.

name

name is the name of the form. If you want to get the dom of the form in js Object, just use the name attribute value directly. For example,

<form action="login.php" method="post" name="loginForm" onsubmit="return check()" enctype="multipart/form-data">
    <input type="text" name="user" id="user" />
    <input type="password" name="pwd" />
    <input type="file" />
    <input type="submit" value="提交" />
</form>

When using js for verification, you can directly use myform.user.value to get the value of the user box. The result is the same as document.getElementById('user') Consistent

onsubmit

onsubmit event attribute, only used in form forms, triggered when the form is submitted, generally can be used for front-end verification. When "submit" When the button is clicked, the check() function is executed. In the check() function, we perform empty verification on the form input box. If it is empty, prompt for input and return false, so that the form will not be submitted. At the same time, when using Note that onsubmit cannot lose return, otherwise the form will always be submitted.

enctype

The enctype attribute specifies the mode for encoding form data before sending to the server. By default it is: application/x-www-form -urlencoded, that is, when we do not write the enctype attribute, its other multipart/form-data value is not encoded and does not encode characters. This value is required when using a form that contains a file upload control.

The above is the detailed content of What are the commonly used attributes in php forms?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn