Welcome Guest, Not a member yet? Register   Sign In
Need help using valid_url rule reference
#1

(This post was last modified: 05-11-2015, 06:09 PM by eldan88.)

Hey Guys,

I am trying to use the valid_url rule in CodeIgniter and it doesn't seem to be working.

When I submit the form by just typing it "test" it doesn't display any kind of validation error. I'm not sure what is wrong here.

If anyone can help me out I would really appreciate it. Thanks!




PHP Code:
private  function validateForm(){


 
   $this->form_validation->set_rules("proj_url","project URL""required|valid_url",[
 
       "required" => "Please enter a project url",
 
       "valid_url" => "Please enter the %s in the correct url format (www.myproject.com)"
 
   ]);




Reply
#2

Is the required rule working? I ask because that code just sets up the rules. To send the submitted data to validation, you have to use.
PHP Code:
if ($this->form_validation->run())
{
 
   // form data validated ok
}
else
{
 
   // form data failed validation

Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply
#3

Yes the required rule is working.I had to change the core function of valid_url... for some reason it wasn't working properly
Reply
#4

It is working properly, 'test' is a valid hostname and therefore a valid URL too, no matter how strange that may seem at first.
Reply
#5

(This post was last modified: 05-12-2015, 04:56 AM by Avenirer.)

@eldan88 what do you mean it wasn't working properly? "test" IS a valid url. If you want, after validation you can at any time do a prep_url() on the value.
Reply
#6

I had the same issue.. I would post "224regqawergwgw" without any domain identifier and still return true for valid url...



My solution was to create a callback function and check the string with a filter.


PHP Code:
$this->form_validation->set_rules('add_website''website url''trim|required|callback_check_valid_url'); 



PHP Code:
public function check_valid_url$param )
{
 
 if( ! filter_var($paramFILTER_VALIDATE_URL) ){
 
   $this->form_validation->set_message('check_valid_url''The {field} must be a valid url');
 
   return FALSE;
 
 }else{
 
   return TRUE;
 
 }
 
 

Reply




Theme © iAndrew 2016 - Forum software by © MyBB