4

I have a simple form adding to my db with the below validation rules. "form" is in autoload.php.

Whenever any of the validation rules are broken the page shows no error output, when none are broken the form goes through as expected.

here's my controller function

  public function add()
{

    $this->load->library('form_validation');
    $this->load->library('layout');
    // field name, error message, validation rules
    $this->form_validation->set_rules('type', 'Type', 'required|xss_clean');
    $this->form_validation->set_rules('title_type', 'Title type', 'required|xss_clean');
    $this->form_validation->set_rules('first_name', 'First name', 'trim|required|min_length[1]|max_length[150]|xss_clean');
    $this->form_validation->set_rules('surname', 'Surname', 'trim|required|min_length[1]|max_length[150]|xss_clean');
    $this->form_validation->set_rules('job_title', 'Job title', 'trim|min_length[5]|max_length[300]required|xss_clean');
    $this->form_validation->set_rules('office_number', 'Office number', 'trim|min_length[2]|max_length[11]|xss_clean');
    $this->form_validation->set_rules('telephone', 'Telephone', 'trim|numeric|xss_clean');
    $this->form_validation->set_rules('email', 'Email', 'trim|valid_email|xss_clean');
    $this->form_validation->set_rules('website', 'Website', 'trim|prep_url|xss_clean');
    $this->form_validation->set_rules('background', 'Background', 'trim|xss_clean');


    $data = array(
        'title' => 'Add staff member'
    );

    if ($this->form_validation->run() == FALSE) { //Was errors

        $this->session->set_flashdata('message','You missed some details, please try again.');

        $this->layout->load('default', 'add_person', $data);
    } else {
        $this->people_model->add_person();
        $this->layout->load('default', 'added_person', $data);
    }


} //add

And in my form view i have

    <?php echo validation_errors('<p class="msg msg-error">') ?>

Can anyone see what I've done wrong, I've tried everything I can think of.

A var_dump of the validation_errors() gives

string '' (length=0)

edit: strangely, if i swap these two lines around, i get:

    $this->load->library('form_validation');
    $this->load->library('layout'); //lib code http://pastebin.com/K1rBV512

Message: Undefined property: People::$form_validation

Filename: controllers/people.php

Line Number: 27
2
  • Are you using HMVC extension? Commented Oct 22, 2012 at 15:02
  • @Damien no, the only 3rd party thing im using is the layout library. Here's that: pastebin.com/K1rBV512 Commented Oct 22, 2012 at 15:11

3 Answers 3

1

You need to pass the $data array to your model. All the inputs need to get POST from the VIEW page. You're not showing any specific errors so it's hard to diagnose your problem.

Make sure you POST all the inputs like this in your MODEL:

`'first_name' => $this->input->post('first_name'),`


In your view:

<?php echo validation_errors('<p class="msg msg-error">') ?>

In your view change it to this:

<p class="msg msg-error"><?php echo validation_errors(); ?></p>
Sign up to request clarification or add additional context in comments.

1 Comment

It is like that in my model, and the data goes into the db fine.
0

The error doesn't to seem anything to do with session, but i don't see you loading session library.

1 Comment

database and session are autoloaded
0

I believe problem is in your view, not in the controller. Problem seems to be that your $_POST is empty and there is nothing to validate.

This seems unanswered, hopefully it will help others.

If this happens then try a var_dump on $_POST. If empty then make sure you have the

then inside the make sure you have your inputs with the "name" property on , not the "id"

Hope this helps anyone

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.