CodeIgniter Forums
validation problem - 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 problem (/thread-11615.html)



validation problem - El Forum - 09-16-2008

[eluser]dimis[/eluser]
I want to use the validation library.
I have a <select> input and I want this not to have the value '-1', what I can do?


validation problem - El Forum - 09-16-2008

[eluser]Michael Wales[/eluser]
My first thought, with a <select> input is... don't put -1 within the <option>s - but, just to answer your question.

Code:
function form() {
  $this->load->library('validation');
  $this->validation->set_rules(array(
    'selectbox' => 'required|callback__check_setbox'));
  $this->validation->set_fields(array(
    'selectbox' => 'Your select box'));
}

function _check_setbox($val) {
  if ((int) $val >= 0) {
    return TRUE;
  }
  $this->validation->set_message('_check_setbox', 'Your setbox must be greater than -1.');
  return FALSE;
}



validation problem - El Forum - 09-16-2008

[eluser]Sumon[/eluser]
Is there are any validation like positive_value. I think currently CI don't have it. But this might be nice to have validation with positive_value, negative_value, zero_value.

Might be a request to add tiny feature to CI as well. Wink


validation problem - El Forum - 09-16-2008

[eluser]Mirage[/eluser]
Using ExtJs quite frequently, I've been dabbling with the thought of creating a core lib extension for the Validation class which supports 'validators'. Using the adapter pattern, this would provide a basis for extensible validation....

-m


validation problem - El Forum - 09-16-2008

[eluser]Colin Williams[/eluser]
Put me on your notification list, Mirage. I'd like to see what you're thinking about.


validation problem - El Forum - 09-16-2008

[eluser]Mirage[/eluser]
I'll try to remember that. Most likely you'd read about here anyways.

I first need to look into Ricks beta announcement of the library and how he's adjusted it.

If I do write something, it'd likely be a core extension that provides transparent access to the Zend_Validation Library. I'm more and more growing fond of binding ZF functionality via CI Libraries. One could argue this being pointless as one could then just use ZF directly. The point for me however is to keep with the harmony of 'default' intelligence and config-driven approach of CI. This gives you added power CI style with minimal effort.

Cheers
-m


validation problem - El Forum - 09-16-2008

[eluser]Michael Wales[/eluser]
Check the Wiki as well - I believe xwero (I may have the name wrong) submitted an extended Validation class with a lot of great additions (greater_than, less_than, etc.)