I'm making a URL validation helper which I set as a rule in my form validation.
$this->form_validation->set_rules('link_url', 'Link URL', 'trim|required|xss_clean|max_length[255]|validate_url');
If the validate_url returns FALSE how can I return a custom validation error from the helper?
Helper
if ( ! function_exists('validate_url'))
{
function validate_url($str)
{
$pattern = "/^(http|https):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i";
if (!preg_match($pattern, $str))
{
$this->form_validation->set_message('validate_url', 'URL is not valid');
return FALSE;
}
else
{
return TRUE;
}
}
}
When I submit the form I get
Fatal error: Using $this when not in object context