cutelyst 4.3.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
Cutelyst::ValidatorAccepted Class Reference

Checks if a field is available and has a specific value. More...

#include <Cutelyst/Plugins/Utils/validatoraccepted.h>

Inheritance diagram for Cutelyst::ValidatorAccepted:

Public Member Functions

 ValidatorAccepted (const QString &field, const ValidatorMessages &messages=ValidatorMessages())
 
 ~ValidatorAccepted () override
 
- Public Member Functions inherited from Cutelyst::ValidatorRule
 ValidatorRule (const QString &field, const ValidatorMessages &messages={}, const QString &defValKey={}, QByteArrayView validatorName=nullptr)
 
virtual ~ValidatorRule ()
 Deconstructs the ValidatorRule.
 

Static Public Member Functions

static bool validate (const QString &value)
 Returns true if the value is equal to yes, on, 1, or true.
 

Protected Member Functions

QString genericValidationError (Context *c, const QVariant &errorData=QVariant()) const override
 
ValidatorReturnType validate (Context *c, const ParamsMultiMap &params) const override
 
- Protected Member Functions inherited from Cutelyst::ValidatorRule
 ValidatorRule (ValidatorRulePrivate &dd)
 
QString debugString (Context *c) const
 
void defaultValue (Context *c, ValidatorReturnType *result) const
 
QString field () const noexcept
 
virtual QString genericParsingError (Context *c, const QVariant &errorData={}) const
 
virtual QString genericValidationDataError (Context *c, const QVariant &errorData={}) const
 
QString label (Context *c) const
 
QString parsingError (Context *c, const QVariant &errorData={}) const
 
bool trimBefore () const noexcept
 
QString validationDataError (Context *c, const QVariant &errorData={}) const
 
QString validationError (Context *c, const QVariant &errorData={}) const
 
QString value (const ParamsMultiMap &params) const
 

Detailed Description

The field under validation must be yes, on, 1, or true. This is useful for validating "Terms of Service" acceptance. This check will also fail if the input data for the specified field is empty or if the field is not part of the input data.

Note
Unless validation is started with NoTrimming, whitespaces will be removed from the beginning and the end of the input value before validation.
Return type
On success, ValidatorReturnType::value will be set to true.
See also
Validator for general usage of validators.

Definition at line 34 of file validatoraccepted.h.

Constructor & Destructor Documentation

◆ ValidatorAccepted()

ValidatorAccepted::ValidatorAccepted ( const QString field,
const ValidatorMessages messages = ValidatorMessages() 
)

Constructs a new ValidatorAccepted object for the given field using optional custom error messages.

Definition at line 14 of file validatoraccepted.cpp.

◆ ~ValidatorAccepted()

ValidatorAccepted::~ValidatorAccepted ( )
overridedefault

Destroys the ValidatorAccepted object.

Member Function Documentation

◆ genericValidationError()

QString ValidatorAccepted::genericValidationError ( Cutelyst::Context c,
const QVariant errorData = QVariant() 
) const
overrideprotectedvirtual

Returns a generic error message.

Reimplemented from Cutelyst::ValidatorRule.

Definition at line 43 of file validatoraccepted.cpp.

References QString::arg(), QString::isEmpty(), Cutelyst::ValidatorRule::label(), and Cutelyst::Context::qtTrId().

◆ validate()

ValidatorReturnType ValidatorAccepted::validate ( Cutelyst::Context c,
const ParamsMultiMap params 
) const
overrideprotectedvirtual