8000 Latest validation changes · Issue #661 · atk4/atk4 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jul 25, 2022. It is now read-only.

Latest validation changes #661

Open
ghost opened this issue Nov 10, 2015 · 2 comments
Open

Latest validation changes #661

ghost opened this issue Nov 10, 2015 · 2 comments
Assignees

Comments

@ghost
Copy link
ghost commented Nov 10, 2015
8000

Since the the commit validation does not work for me in my application like before. The application is just ignoring the rules I have set. I will give more info if required.

@romaninsh
Copy link
Member

Can you supply code sample?

@romaninsh romaninsh self-assigned this Nov 10, 2015
@ghost
Copy link
Author
ghost commented Nov 10, 2015

Here is a sample, I provide more if needed:

// create a new view
$form = $this->add('Form', null, null, ['form/minimal']);

$form->setModel('User',false);

$form->controller->importfield('title')
     ->setEmptyText(PAGE_REGISTER_FIELD_TITLE_RADIO);

$form->controller->importfield('forename');
$form->controller->importfield('surname');
$form->controller->importfield('street');
$form->controller->importfield('street_number');
$form->controller->importfield('additional_address');

$form->controller->importfield('zipcode')
                 ->validateField('strlen($this->get()) === 5', PAGE_REGISTER_FIELD_ZIPCODE_ERROR_LENGTH)
                 ->validateField('filter_var($this->get(), FILTER_VALIDATE_INT)', PAGE_REGISTER_FIELD_ZIPCODE_ERROR_NUMERIC);

$form->controller->importfield('city');
$form->controller->importfield('state');

$form->controller->importfield('country');

$form->controller->importfield('telephone'); 

$form->addField('DatePickerDefault', ['name'=>'birthdate'], PAGE_REGISTER_FIELD_BIRTHDATE, null)
     ->validateNotNULL(PAGE_REGISTER_FIELD_NOT_NULL);

$form->controller->importfield('email')->validateField(
        'filter_var($this->get(), FILTER_VALIDATE_EMAIL)', PAGE_REGISTER_FIELD_EMAIL_ERROR
);

$form->controller->importfield('amazon_link');
$form->controller->importfield('additional_link');

$minlength = $this->app->getConfig('registration/reasonminlength');

// TODO: can this be done with an anonymous function
function reasonLimit($length, $minlength)
{
    return (strlen($length) < $minlength) ? false : true;
}

$form->controller->importfield('reason')->validateField(
        'reasonLimit($this->get(),'.$minlength.')', sprintf(PAGE_REGISTER_FIELD_REASON_ERROR_LENGTH, $minlength)//'Bitte geben Sie mindestens '.$minlength.' Zeichen ein.'
);

$form->addSubmit(PAGE_REGISTER_SUBMIT);

// checks if form is submitted
if($form->isSubmitted())
{
    // check if submitted email is already registered
    $email = $form->get('email');
    $q = $this->app->db->dsql();
    $q->table('user');
    $q->where('email',$email);
    if(count($q->get()) === 0)
    {


        // add data to the db
        $form->save();


        $form->js()->univ()->successMessage(PAGE_REGISTER_SUCCESS)
                           ->reload()
                           ->execute();


    }
    else
    {
        // display a error message
        $form->js()->univ()->errorMessage(PAGE_REGISTER_FAILED)->execute();
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0