What is a good way to process data from a form before applying business logic in PHP?

I think this is a common problem.

Whenever there is a form on a web page, a PHP file is created on the inside of the file that processes the data submitted from the form. You start with $_POST. You need to make sure that the element names I do not rigged, not enlarged or reduced, and you want to input elements were not empty and you need to avoid the quotes, so you may need to use the isset(), empty(), mysql_real_escape_string()and other functions to perform this routine work before applying business logic to this data.

What is the best way to do this chore?

I want to write less code and make it reliable.

There may not be a better way, but at least there are good ways to do this. How to do it?

For convenience, assume that there is data such as username, password, title, content, question, answer,unit_price,...

What if I do not use the PHP framework?

+3
source share
3 answers

IMHO,

The Zend_Form component provides a good reliable way to reuse for such tasks.

+4
source

RageZ Zend_Form... , () Zend_Form. Zend_Filter_Input, Zend_Form ( ). , Zend_Form, conciser.

PHP , Zend_Form/Zend_Filter_Input , .

+2

, , Zend Framework.

, PHP >= 5.2.0, ext/filter , .

+1
source

Source: https://habr.com/ru/post/1723071/


All Articles