Welcome Guest, Not a member yet? Register   Sign In
FYI - Validation takes forever
#1
Big Grin 

I don't really seem to have anyplace else to talk about this at the moment and just needed to share, so forgive me. But - man! - writing the Validation library seems to be taking forever. I'm getting close, I really am, but seems there's always more when I turn around. Smile

Since I'm here, though, here's a brief overview of the goodies the new Validation library setup is giving you:

  1. Validation isn't tied for $_POST, but easily used with any set of data now. Though it's simple to use with your normal $_POST data also.
  2. Easier than ever to write custom rules. They're now classes that can live anywhere, and you just need to set the class' location in the config file. This also makes it simple to organize different types of rules so they can be re-used from project to project, and only load the ones you need.
  3. The Controller provides a convenience method for working with $_POST data that has been submitted.
  4. Validation is also built into the Model if you want to use it there, either alone or in combination with the Controller validation. There are times when one makes more sense than the other.
  5. The display of errors now uses view files so you can easily customize the output, and even provide several options if you need the HTML to be different in different locations.
  6. Files are now treated as any other form input, as far as validation goes, and new validation rules exist for validating file mime types, extensions, size on disk, ensure it's an image, and even ensure the dimensions of the image are within your requirements.
  7. For those doing ecommerce work, we also now have credit card numbering verification for 20 different card types, including 6 in Canada, a Chinese card, and at least one Russian card. This doesn't validate the card number only ensures it matches the requirements for that card type to be a possible real card.
  8. OH! One of the things that started me down this path in the first place - new required_with, required_without, and enhanced is_unique methods should now make it possible to use the same rules for both creating and updating records.

Whew! There's probably more, but that's the big stuff that comes to mind right now. You guys asked for something slightly more flexible and powerful, and I think this delivers. Hope to have this integrated into the main CI4 repo within the next week or so.
Reply
#2

@kilishan, Thank's a lot for the update information.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

+ 1000 for being able to do validation in Models. I'm assuming (hoping) this also includes being able to do callbacks in a model because i see that come up on stack all the time.

awesome that you are thinking of the e-commerce developers. doing that pre-validation on the credit card number is actually really important because you can catch potential user mistakes without having to run the transaction, and give them a specific error message.

thanks for posting this report and overall all these new features are great and also really practical.
Reply
#4

Whew! I think it's all in place. I guess we'll find out what I missed as people start playing with it. Smile If you want to take a peek at the docs without downloading the entire framework, then head over to GitHub.

(09-20-2016, 01:14 PM)cartalot Wrote: + 1000 for being able to do validation in Models. I'm assuming (hoping) this also includes being able to do callbacks in a model because i see that come up on stack all the time.

Well, callbacks aren't really needed honestly, since everything can be classes that can be used. For the time being, callbacks don't have any special support. Just the RuleSets. That definitely might be something to look at putting back in, though, as I think about it a little more. Was just hoping to reduce the complexity a little bit, so this one will need a bit of a think through on pros vs cons.

(09-20-2016, 01:14 PM)cartalot Wrote: awesome that you are thinking of the e-commerce developers. doing that pre-validation on the credit card number is actually really important because you can catch potential user mistakes without having to run the transaction, and give them a specific error message.

Absolutely! I spent 3 years working for a company that supported and built custom payment gateway solutions for a couple of their products, and it was definitely something that would have been nice to have back then.
Reply
#5

+1 for easier ways to write custom rules.

The callback process was kinda laborious so a more modular way to do that would be great.

Thank you!
Reply
#6

(This post was last modified: 09-22-2016, 05:25 PM by cartalot.)

Read the Docs page you linked. I'm not quite understanding the calling of custom view files to show the errors? I guess you mean having a view file that is directly above the view file containing the form? That said - if we want to have the error show up next to the relevant form field - similar to how in CI 3 we use form_error('fieldname') - we would use this?
Code:
$validation->getError('fieldname');
Reply
#7

Update: user guide updated, incorporating latest changes ... https://bcit-ci.github.io/CodeIgniter4/
James Parry
Project Lead
Reply
#8

(09-22-2016, 05:18 PM)cartalot Wrote: Read the Docs page you linked. I'm not quite understanding the calling of custom view files to show the errors? I guess you mean having a view file that is directly above the view file containing the form? That said - if we want to have the error show up next to the relevant form field - similar to how in CI 3 we use form_error('fieldname') - we would use this?
Code:
$validation->getError('fieldname');

Guess I need to do some editing on those docs, then.

But you don't have to call a custom view file. It's all handled in the background when you use $validation->listErrors() or $validation->showError(). For the single line error, you'd use showError('fieldname') if you wanted it to output a styled and HTML-ified version of the error. If you just want the plain error text, you would use getError('fieldname').
Reply
#9

I always wanted it this way. Thank you. :-)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB