Jump to content
  • 0

Universal Module Customs Validation


aneip

Question

I need to validate unique subdomain for a service that use universal module but the documentation is a bit of lacking. The example really fix into my requirement as in this page http://docs.blesta.com/display/dev/Error+Checking under custom rules. 

 

I create a service option called subdomain, type text in universal module. I can see this configurable options in the order form. Now I need to check for it's uniqueness. Can anybody help me? 

 

As I said, the example almost the same as my requirement. But I not sure where to start. Where do I wrote the custom code? How do I get my custom code be called when blesta validate the option?

 

 

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

You can't define custom rules like that on the Universal Module through the interface. There is no way to define the callback validation method.

 

If you don't mind writing custom code that you will need to maintain between Blesta releases, you can update the Universal Module directly under /components/modules/universal_module/universal_module.php and add your callback method.

Link to comment
Share on other sites

  • 0

Got it, if that's the only way..

 

Maybe the suggestion for feature release, we can define the required class and function name in Universal Module interface, just like built-in rules. Then the code will load required file/class and invoke the function for validation. So the 3rd party just need to maintain the validation part only..

Link to comment
Share on other sites

  • 0

I have another question related to this. I'm doing pretty much the same thing. One of my coworkers brought up an interesting corner case: what if a client orders two services with the same subdomain? Is the entire order atomic, or is each service in the order atomic?

 

That is, if I write a callback function to ensure that the subdomain that a customer chooses is not taken, and it checks the module rows to see if such a subdomain already exists, if the hostname was not taken prior to the order being placed, will the function return the same result for both services in the same order, or will it place one order and then run validation again?

 

I assume that the entire order is atomic, and that if a customer orders two subdomains called "foo" in the same order, such a function won't catch this.

 

Is it possible to refer to other services in the order in the validation function? Is there some other way y'all would recommend going about this validation?

Link to comment
Share on other sites

  • 0

The validation is only concerned with user input for a package per order, and the universal module does not validate the uniqueness of any fields. You can validate the user input yourself to check for duplicates in a callback method, likewise you can query the database to check for existing duplicate data as well. Here's a general example. You would just expand on the callback method to perform the necessary checks.

Link to comment
Share on other sites

  • 0

Services are validated independently of one another, so you wouldn't know anything about a second service at the time the module is attempting to add the first. Any validation on multiple services before any have been added must be done at a higher level. The Order plugin, for example, iterates over each service when adding them. Before that happens, you could correlate all service data and perform your custom validation. There would likely be more involved in this than simply creating a new validation rule.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...