User Tools

Site Tools


programmieren:fortgeschritten:validierung

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

programmieren:fortgeschritten:validierung [2026/07/31 09:22] – created adminprogrammieren:fortgeschritten:validierung [2026/09/16 16:09] (current) – created kinda admin
Line 1: Line 1:
-validierung+====== Datavalidation ====== 
 + 
 +Datavalidation is a very important component of an application that contains end user inputs. 
 + 
 +It ensures that no malicious, weird or just plain wrong data reaches to the database, usually its also used to inform a user about what they did wrong so they can correctly enter their data. 
 + 
 +Validation works by comparing the given data to certain ruleset and if it matches it can be persisted, if it doesn't match it will not persist and probably rollback the entire submit operation. 
 + 
 + 
 +PHP itsself and CakePHP add alot of prepared functions that already implement that rule check. 
 + 
 +In CakePHP you can simply use the validator that is called for its respective table when an entity is supposed to be saved, ontop of the validator you can call the individual rules per database column, for example 
 + 
 +<code php> 
 +$validator 
 +    ->integer('cancellation_deadline') 
 +    ->notEmptyString('cancellation_deadline') 
 +    ->requirePresence('cancellation_deadline') 
 +    ->range('cancellation_deadline', CancellationDeadline::RANGE); 
 +</code> 
 + 
 +CakePHP already prepares the validation messages itsself, they do not need to, but can be set manually. 
 + 
 +In CakePHP validation messages are displayed right under their respective form field (if there is a form). 
 + 
 +Thats how that looks: 
 +{{:programmieren:fortgeschritten:validation.png?800|}}
programmieren/fortgeschritten/validierung.1785482538.txt.gz · Last modified: by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki