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

[eluser]williamparry[/eluser]
Hi,

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

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

In the controller folder I have:

Code:
<?php

class Register extends Controller {
    
    function index()
    {
(etc)

The page is located at:

http://127.0.0.1/website/index.php/register

When I submit the form, it goes:

http://127.0.0.1/website/index.php/regis...p/register

Why is appending the index.php again?

Thanks
#2

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

It should be:
Code:
$config['base_url'] = "http://127.0.0.1/website/";
#3

[eluser]williamparry[/eluser]
Ah that did it!

Thanks.

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?
#4

[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:
Code:
$_POST['whatever'];

You should use:
Code:
$this->input->post('whatever');

Hopefully that answers your question.
#5

[eluser]williamparry[/eluser]
I'm a bit confused about how the validation ties in with post. I have:

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

If I do
Code:
$this->input->post('firstName');

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?

Cheers
#6

[eluser]Pascal Kriete[/eluser]
When you run the validation using:
Code:
$this->validation->run()
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:
Code:
$this->load->model('Your_model');

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

foreach ($fields as $field) {
    $this->Your_model->addField($field);
}
#7

[eluser]nirbhab[/eluser]
hi
in your configration file you wud find this line.


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

change it to

Code:
$config['index_page'] = "";

and try using your form post.

it might help you out.
#8

[eluser]williamparry[/eluser]
It doesn't seem to be md5ing my password.

Code:
$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_fields($fields);
        $this->validation->set_error_delimiters('<div class="error">', '</div>');
        $this->validation->set_rules($rules);
        
        $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:

Code:
$fields['phoneNumber']

It says:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Validation::$phoneNumber

Filename: views/register.php

Line Number: 21
#9

[eluser]nirbhab[/eluser]
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.
#10

[eluser]xwero[/eluser]
There is no phoneNumber rule




Theme © iAndrew 2016 - Forum software by © MyBB