mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
More work on the form vlaidator.
This commit is contained in:
parent
1b4ecafa2c
commit
7e8a7671e4
@ -214,7 +214,7 @@ FormNeedsOtherCharacterFieldEntry::~FormNeedsOtherCharacterFieldEntry() {
|
||||
//FormMinimumLengthFieldEntry
|
||||
|
||||
bool FormMinimumLengthFieldEntry::validate(Request *request, const FormField *field, const std::string &data, std::vector<std::string> *errors) {
|
||||
if (data.size() <= min_length) {
|
||||
if (data.size() < min_length) {
|
||||
if (errors) {
|
||||
std::stringstream ss;
|
||||
|
||||
@ -241,7 +241,7 @@ FormMinimumLengthFieldEntry::~FormMinimumLengthFieldEntry() {
|
||||
//FormMaximumLengthFieldEntry
|
||||
|
||||
bool FormMaximumLengthFieldEntry::validate(Request *request, const FormField *field, const std::string &data, std::vector<std::string> *errors) {
|
||||
if (data.size() >= max_length) {
|
||||
if (data.size() > max_length) {
|
||||
if (errors) {
|
||||
std::stringstream ss;
|
||||
|
||||
@ -448,6 +448,19 @@ FormField *FormField::need_to_match(const std::string &other) {
|
||||
return this;
|
||||
}
|
||||
|
||||
FormField *FormField::ignore_if_not_exists() {
|
||||
_ignore_if_not_exists = true;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
FormField *FormField::ignore_if_other_field_not_exists(const std::string &other) {
|
||||
_ignore_if_other_field_not_exists = true;
|
||||
_ignore_if_other_field_not_exist_field = other;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
void FormField::add_entry(FormFieldEntry *field) {
|
||||
fields.push_back(field);
|
||||
}
|
||||
@ -455,6 +468,18 @@ void FormField::add_entry(FormFieldEntry *field) {
|
||||
bool FormField::validate(Request *request, std::vector<std::string> *errors) {
|
||||
std::string param = request->get_parameter(name);
|
||||
|
||||
if (_ignore_if_not_exists && param == "") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_ignore_if_other_field_not_exists) {
|
||||
std::string op = request->get_parameter(_ignore_if_other_field_not_exist_field);
|
||||
|
||||
if (op == "") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool valid = true;
|
||||
|
||||
for (int i = 0; i < fields.size(); ++i) {
|
||||
@ -467,6 +492,8 @@ bool FormField::validate(Request *request, std::vector<std::string> *errors) {
|
||||
}
|
||||
|
||||
FormField::FormField() {
|
||||
_ignore_if_not_exists = false;
|
||||
_ignore_if_other_field_not_exists = false;
|
||||
}
|
||||
FormField::~FormField() {
|
||||
for (int i = 0; i < fields.size(); ++i) {
|
||||
|
@ -152,6 +152,11 @@ public:
|
||||
std::string name;
|
||||
std::string human_name;
|
||||
|
||||
bool _ignore_if_not_exists;
|
||||
|
||||
bool _ignore_if_other_field_not_exists;
|
||||
std::string _ignore_if_other_field_not_exist_field;
|
||||
|
||||
FormField *need_to_exist();
|
||||
FormField *need_to_be_int();
|
||||
FormField *need_to_be_float();
|
||||
@ -164,6 +169,8 @@ public:
|
||||
FormField *need_maximum_length(const int max_length);
|
||||
FormField *need_to_be_email();
|
||||
FormField *need_to_match(const std::string &other);
|
||||
FormField *ignore_if_not_exists();
|
||||
FormField *ignore_if_other_field_not_exists(const std::string &other);
|
||||
|
||||
void add_entry(FormFieldEntry *field);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user