Is there an easy way to handle forms with PHP?

2019-08-18 10:56发布

问题:

Dealing with forms in PHP has always given me major headaches. Primarily formatting; handling punctuation inside a form input, manipulating strings for database insertions, stripping when retrieving from database, etc.

Is there an easy alternative to strip_slashes and all that junk? I don't want a tool like a form wizard that does everything for you - I still would like a high level of customization. What would be nice though is a tool that says "I want this text field to connect to this database field.", then it handles all that tedious work.

回答1:

Look up PHP PDO. It makes it quite nice to handle all of the database stuff. As for mapping forms. . . You'd need another application (if one exists out of the box) to handle that.



回答2:

You should look into PHP frameworks which are specifically designed to support systems involving user input.

Personally I've used CakePHP and it's been very useful (though it does tend to assume you have a fairly simple data model and you don't mind creating it from scratch). It's highly customisable (you create all form components yourself) and if you use its full capabilities it will handle slashes and database fields and all the rest.

Other frameworks are available...