Home > PHP Framework > ThinkPHP > ThinkPHP has three ways to collect form data

ThinkPHP has three ways to collect form data

藏色散人
Release: 2021-08-27 09:29:00
forward
2683 people have browsed it

This article will introduce the three methods of ThinkPHP to collect form data into the database in the tutorial column of thinkphp. I hope it will be helpful to friends in need!

ThinkPHP collects form data into the database (three ways)

1. Assume there is a form

ThinkPHP has three ways to collect form data

Note: __SELF__ returns the path of the method where the controller is located. You can print echo __SELF__ in the controller method;
You can check whether {$smart.const.__SELF__} has been parsed through firebug

2. Collect form data

Method 1. Through $_POST method

The data $_POST received in the controller is an array, and then you can add the form through the add() method Data.

ThinkPHP has three ways to collect form data

Method 2. Through AR, it is more flexible

ThinkPHP has three ways to collect form data

Because some data do not want to be stored in the database , all data can be added in this way.

Method 3. Through the create() method, note that this method is only responsible for helping us collect data, but does not help us add data to the database.

ThinkPHP has three ways to collect form data

Note: If we write the name attribute in the form incorrectly, for example:

ThinkPHP has three ways to collect form data

There is no such name in the data table goods_number_number field, the create() method will automatically filter out this field for us.

How to filter in the specific framework?

ThinkPHP has three ways to collect form data



When we add the database successfully, we need to return to the add page. The above way of writing is too ugly. We can call $this-> ;success('prompt information','generate URL address through U function'); and$this->error('error prompt information','url address')

ThinkPHP has three ways to collect form data

Recommended: "The latest 10 thinkphp video tutorials"

The above is the detailed content of ThinkPHP has three ways to collect form data. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template