php form form concept

The input field mark introduced by PHP form element < input >

Input field flag < input >

The input field tag < input > is one of the most commonly used tags in forms. Common input field markers < input > include text box, button, radio button, check box, etc.

type attribute values and examples and descriptions:

1. text


<input type="text" name="user" value="user" size="12" maxlength="100">

Description: name is the name of the text box, value is the default value of the text box, size is the width of the text box (in characters), and maxlength is the maximum number of characters entered in the text box.

2. password


pwd:<input type="password" name="pwd" value="123456" size="12" maxlength="16"><br>

In the password field, the characters entered by the user in the text box will be replaced with "*", so as to play a role of confidentiality.

3. file


file:<input type="file" name="file" enctype="multipart/form-data" size="12" maxlength="100"><br>

Note: File domain, when a file is uploaded, it can be used to open a mode window to select a file. Then upload the file to the server through the form, such as uploading word file, etc. It must be noted that when uploading a file, you need to indicate the attribute enctype = "multipart / form data" of the form to realize the upload function.

4. radio


        gender:<input type="radio" name="gender" value="0">male 
               <input type="radio" name="gender" value="1">female 
               <input type="radio" name="gender" value="2">unknow 

Note: the radio button is used to set a group of options. The user can only select one. The checked property is used to set that the radio button is selected by default.

5. checkbox


        goods:<input type="checkbox" name="goods" value="0">goods1 
               <input type="checkbox" name="goods" value="1">goods2 
               <input type="checkbox" name="goods" value="2">goods3

6. submit


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

7. reset


<input type="reset" name="reset" value="reset">

Description: clear and reset the form content. It is used to clear the content of all text boxes in the form and restore the selection menu items to their original values.

8. button


<input type="button" value="i am button">


Examples are as follows:

<input type="hidden" name="id">

Description: hidden field, used to submit variable values implicitly in the form. Hidden domain is invisible to users in the page. The purpose of adding hidden domain is to collect or send information in a hidden way. When the browser clicks the send button to send the form, the information of the hidden field is also sent to the processing page specified by the action.


Selection field mark and text field mark introduced by PHP form element

Select domain tags < Select > and < option >

1. List method


<select name="lag" id="lag">
    <option value="0" selected>php</option>
    <option value="1">thinkphp</option>
    <option value="2">laravel</option>

The operation results are as follows:




2. Menu mode

<select name="lag" id="lag" multiple>
    <option value="0" selected>php</option>
    <option value="1">thinkphp</option>
    <option value="2">laravel</option>

The operation results are as follows:




Note: the multiple attribute is used in the < Select > tag of the menu list. Users who specify this option can use the shift and ctrl keys to select multiple items.

Tip: in the above description, only the method of adding static menu is given, and in the process of web program development, menu items can also be added dynamically through loop statements.


Text field mark < textarea >

The text field tag < textarea > is used to create a multiline text field in which more text can be entered.

Ming: text field, also known as multiline text box. The edit warp attribute for multiline text is auto wrap by default.

The following is a specific example to understand the difference between the warm attribute hard and the soft newline tag. The example code is as follows:

<form action="" method="post">
<select name="lag" id="lag" multiple>
    <textarea name="a" cols="20" rows="3" wrap="soft">This is a piece of text to demonstrate: soft enter</textarea>
    <textarea name="b" cols="20" rows="3" wrap="hard">This is a piece of text to demonstrate: hard enter</textarea>
    <input type="submit" name="submit" value="Submit">

    echo nl2br($_POST['a']).'<br>';
    echo nl2br($_POST['b']).'<br>';    

When HTML tags get strings in a multiline edit, they do not display a newline tag. The above example will output the following results:



Creating PHP forms

create form

Create a form by using the < form > tag and inserting the relevant form information into it. The structure of the form is as follows:

<form name= "form_name"  method="method" action="url" enctype="value" target="target_win">

             // Insert some form elements


The < form > tag attributes are as follows:


The attribute values of target are as follows:


Note: the get () method is to append the form content to the URL address and send it; the POST() method is to send the information in the form as a data block to the handler on the server, and the submitted information will not be displayed in the address bar of the browser. The default method for the method property is GET().

Tags: PHP Attribute Laravel

Posted on Fri, 22 May 2020 00:53:02 -0400 by farsighted