Welcome Guest, Not a member yet? Register   Sign In
Form submit using wrong path


I have a registration page and the top of the html in the view folder is:

<?=form_open('register'); ?>

In the controller folder I have:


class Register extends Controller {
    function index()

The page is located at:

When I submit the form, it goes:

Why is appending the index.php again?


[eluser]Pascal Kriete[/eluser]
Make sure that the 'base_url' in your config file is set correctly.

It should be:
$config['base_url'] = "";

Ah that did it!


It looks as though when I add a form element in the view page, I have to add something related to that element on the control page. Is this correct?

[eluser]Pascal Kriete[/eluser]
The form returns a post array as it does in normal php, but in CI you have the validation class to help you check and process the data.

Also instead of accessing the post array directly:

You should use:

Hopefully that answers your question.

I'm a bit confused about how the validation ties in with post. I have:

$rules['firstName'] = "trim|required|xss_clean";

If I do

Will that give me the post variable with the cleaning and validation done?

I've got a registration model set up that is going to deal with the adding and I am not sure how to go about passing the information from the controller to the model. At the moment I am calling the model and running my model's adding function with the argument being $_POST but I don't need some of the fields. Should I do this all by hand and also, can I pass the validated and sanitised post data into the model, rather than raw $_POST without manual coding?


[eluser]Pascal Kriete[/eluser]
When you run the validation using:
All your post data is changed according to the validation rules you set for each field.

As for the model, in CodeIgniter the model is simply another layer, unlike in rails where it is tightly connected to the database. You pass data to it the way you would to any other function. It's basically just a place for your database calls.

If you have a lot of fields (but don't want all of them) you might consider making an array of those you want to add and then looping through that:

// Array of field names to be added
$fields = array('field1', 'field2'...);

foreach ($fields as $field) {

in your configration file you wud find this line.

$config['index_page'] = "index.php";

change it to

$config['index_page'] = "";

and try using your form post.

it might help you out.

It doesn't seem to be md5ing my password.

$rules['firstName']        = "trim|required|xss_clean";
        $rules['lastName']        = "trim|required|xss_clean";
        $rules['password']        = "trim|required|matches[passwordConf]|md5";
        $rules['passwordConf']    = "trim|required";
        $rules['emailAddress']    = "required|valid_email|checkEmailAddress";
        $fields['firstName']    = 'First name';
        $fields['lastName']        = 'Last name';
        $fields['password']        = 'Password';
        # $fields['phoneNumber']    = 'Phone number'; If I don't have this in, it will crash
        $fields['passwordConf']    = 'Password Confirmation';
        $fields['emailAddress']    = 'Email Address';

        $this->validation->set_error_delimiters('<div class="error">', '</div>');
        $inputData    = array(
                            'firstName'        => $this->input->post('firstName'),
                            'lastName'        => $this->input->post('lastName'),
                            'password'        => $this->input->post('password'),
                            'emailAddress'    => $this->input->post('emailAddress'),
                            'phoneNumber'    => $this->input->post('phoneNumber'),
                            'city'            => $this->input->post('city'),

If I don't put in:


It says:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Validation::$phoneNumber

Filename: views/register.php

Line Number: 21

it will as your view page where you must be refilling the code must be calling this field.

n for md5ing, y don't u use md5() ,default php function while storing in database.

There is no phoneNumber rule

Theme © iAndrew 2016 - Forum software by © MyBB