CodeIgniter Forums
validation not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: validation not working (/thread-36114.html)



validation not working - El Forum - 11-21-2010

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

can somebody help me out with this please

Thanks


validation not working - El Forum - 11-21-2010

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


validation not working - El Forum - 11-21-2010

[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


validation not working - El Forum - 11-21-2010

[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);
  }
}



validation not working - El Forum - 11-21-2010

[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;
}
}
?>


validation not working - El Forum - 11-21-2010

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


validation not working - El Forum - 11-22-2010

[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.


validation not working - El Forum - 11-23-2010

[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


validation not working - El Forum - 11-23-2010

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