Support » Plugin: WP MVC » WP MVC Validation of form fields generates error without description

  • Resolved Prabhu Bakiyaraj Chelladurai

    (@prabhuchelladurai)



    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]: http://i.stack.imgur.com/0wf50.png

    In the model, I have given the validation code:

    /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

    https://wordpress.org/plugins/wp-mvc/

Viewing 1 replies (of 1 total)
  • The create_or_save() function is added to admin_controller of every model to validate the fields.

    I don’t know whether this is the only available solution, and is legal, but the issue is solved as of now.

    This method is in contrast to the policy of ‘code-reusability’ and until an alternate solution is created, I am left, but noway, to follow this method.

    Thanks all.

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