add form data with thinkpphp add method

Posted by trammel at 2020-03-30

Last update: 2011-02-16 21:43 read: 79410

Add form data

Let's take a look at an example of submitting form data and writing it to a data table.

create form

Enter the template directory tpldefaultindex (if the index folder does not exist, create one). The index folder corresponds to the template file where the index module (indexaction. Class. PHP) is stored. It cannot be named randomly.

__URL is a special string in the ThinkPHP template. Before outputting the template, the system will automatically replace it with the URL address of the current module. Here is to replace it with myapp / index.php/index. For details, please refer to the special string replacement of ThinkPHP template. In this example, action "\\\\ / insert2" means to submit data to the insert2 operation of the current module.

Tip: because it is only a simple output form.html page without other logical operations, you do not need to create corresponding operations in the index module.

Create write data operation

In the indexaction controller (LIB / action / indexaction. Class. PHP), add the insert2() action:

Fill in the data in the form page and submit it. In ThinkPHP, the data sent by the form is also accepted through the $_post / $_getvariable.


For the submitted form data, ThinkPHP does the addslashes() operation to escape the special characters before the data is written to the data table. If you do not want to escape special characters, you can add slashes () before writing to the database.

Reference reading