Welcome Guest, Not a member yet? Register   Sign In
validation not working
#1

[eluser]diasansley[/eluser]
hello
i have used the same validation example from here http://ellislab.com/codeigniter/user-gui...ation.html
but when i click submit my URL changes to example.com/index.php/form.

can somebody help me out with this please

Thanks
#2

[eluser]pickupman[/eluser]
Edit your /application/config/config.php to point to the correct url in $config['base_url'] to your domain name.
#3

[eluser]diasansley[/eluser]
i have changed it to the foll
http://localhost/CodeIgniter/

where CodeIgniter is the folder when i click submit it redirects to http://localhost/CodeIgniter/form
but form is my controller

Any help will be appreciated

Thanks
#4

[eluser]pickupman[/eluser]
You can have Codeigniter in a subfolder. You will need to have .htaccess in your /CodeIgniter folder to point to index.php since you have removed it from your urls.
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Now for your form based on the link you show, you should have this in your view
Code:
echo form_open('form');

In your controller
Code:
class Form extends Controller{
  function __construct(){
    parent::Controller(); // or you can use parent::__construct();
  }

  function index(){
     $this->load->library('form_validation');

     if($this->form_validation->run()){
          //Do stuff
     }
     $this->load->view('your_view', $data);
  }
}
#5

[eluser]diasansley[/eluser]
here is the code now it says page cannot be found plz help

<?php
class Form extends Controller{
function _construct(){
parent::Controller();
}
}
function index()
{
$this->load->helper(array('form', 'url'));

$this->load->library('validation');

$rules['username'] = "callback_username_check";
$rules['password'] = "required";
$rules['passconf'] = "required";
$rules['email'] = "required";

$this->validation->set_rules($rules);

if ($this->validation->run() == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
}

function username_check($str)
{
if ($str == 'test')
{
$this->validation->set_message('username_check', 'The %s field can not be the word "test"');
return FALSE;
}
else
{
return TRUE;
}
}
?>
#6

[eluser]diasansley[/eluser]
thanks it works...
:-)
#7

[eluser]pickupman[/eluser]
Glad you got it working. Please note that the validation library has been deprecated 1.7.2 (removed in 2.0beta). You should form_validation library instead.

Also, it may be wise to set your username_check to a private method, as someone could visit that page right now. Or change your syntax to
Code:
$this->form_validation->set_rules('username', 'username', 'required|trim|callback__username_check');
$this->form_validation->set_rules('password', 'password', 'required|trim');
$this->form_validation->set_rules('passconf', 'password confirmation', 'required|trim|matches[password]');
$this->form_validation->set_rules('email', 'email address', 'required|trim|valid_email');

//Callback
function _username_check($str){
  if($str == 'test'){
     $this->form_validation->set_message('_username_check', 'The %s field can not be the word "test".');
     return FALSE;
  }
  return TRUE;
}

Also for those of us helping, using the code button in the editor will format your code so we can copy and paste it.
#8

[eluser]diasansley[/eluser]
i have anoter question
i wan to display that "PAGE in IMPERTINENCE" when ever a user clicks on a link that has not yet designed . say in the view can i use the anchor tag as well?


Thanks rgds
#9

[eluser]pickupman[/eluser]
Sure you can load the url helper, and use anchor(). Links not yet completed will show a CI 404 error.




Theme © iAndrew 2016 - Forum software by © MyBB