Magento: Filtering _Naughty Words_ for a Products Custom Options text field
Title pretty much says it but, when adding a Custom Options text field, I wo开发者_高级运维uld like to create an array or a word list filter in the case the user tries to enter some Naughty Words or the like instead of their name. I know how to create a word list filter, but I am unaware how to link it into Magento. Could someone help with pointing out were to look?
Thanks ahead of time.
I would all make it in JS. I am more familiar with jQuery but it's really up to you. The principle would be to have an event listener on the onBlur of your fields (give them a class so you can assign the listener to all of them in one go). Check the content of the field against your database of "naughty words". If it's naughty, set the input class to be "failed" (the same class Magento usually gives, i think it's validation-failed). This way, the form can't be submitted anyway. Don't forget an "else" to remove the failed class if there was one.
You can do this on the frontend. I have no code for you, but here is the general idea:
Add a script to your product page. If you want to get started you can put this in the description field, later you can add this as a separate script in page.xml as an addJs entry.
With the script wait for on DOM load. Then attach a validate-ajax class to the form textbox elements where the called function is also in your script. This will pass the textbox value to the function.
As for your function:
Put a Prototype send and get the response ajax call together. Get this to talk to your custom validation code on the server.
The advantage of this technique is that you will not have people have to wait to be told their text is okay or not. It all happens before form submit.
http://www.magentocommerce.com/wiki/5_-_modules_and_development/admin/xml_structure_for_admin_configurations
精彩评论