• I validated my form fields with the method given in WP MVC and it flashes just the bar and no description was given in the bar. I have added here the code and the screenshot. Any wild guess or idea to repair this?

    ![Add Currency Error][1]

    [1]: https://i.stack.imgur.com/0wf50.png

    In the model, I have given the validation code:

    /w2-store/app/model/currency.php
    
    var $validate = array(
        'currency_title'    =>  array(
                    'rule'      =>  'not_empty',
                    'pattern'   =>  '/^[A-Za-z]/',
                    'message'   =>  'Enter Capitalized Currency Title'),
    
        'currency_code'     => array(
                    'rule'      =>  'not_empty',
                    'pattern'   =>  '/[A-Z]/',
                    'message'   =>  'Enter Currency Code - CAPITAL Alphabets only'),
    
        'currency_numeric_code' => array(
                    'rule'      =>  'not_empty',
                    'rule'      =>  'numeric',
                    'message'   =>  'Enter Currency Numeric Code - Only Numbers')
     );

    And the create_or_save() function in the admin_controller is overwritten like this:

    public function create_or_save() {
    
    if (!empty($this->params['data'][$this->model->name])) {
        $object = $this->params['data'][$this->model->name];
        if (empty($object['id'])) {
            // This 'if' is necessary for the fields in the form to be validated
            if ($this->model->create($this->params['data'])) {
                $id = $this->model->insert_id;
                $url = MvcRouter::admin_url(array('controller' => $this->name, 'action' => $this->_redirect_action, 'id' => $id));
                $this->flash('notice', 'Successfully created!');
            }
            else
            {
                $this->flash('error', $this->model->validation_error_html);
            }
            $this->redirect($url, $msg);
        }
        else
        {
            if ($this->model->save($this->params['data'])) {
                $this->flash('notice', 'Successfully saved!');
                $url = MvcRouter::admin_url(array('controller' => $this->name, 'action' => $this->_redirect_action, 'id' => $id));
                $this->redirect($url);
            }
            else
                {
                    $this->flash('error', $this->model->validation_error_html);
                }
            }
        }

    In the above code, the third ‘if’ condition is the one meant for successful validation, but it is skipped and the first ‘else’ condition is met only to display the screenshot given above.

    Awaiting useful help/ideas/guesses.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WP MVC Validation of form fields generates error without description’ is closed to new replies.