开发者

html Form validation in js

开发者 https://www.devze.com 2022-12-18 11:43 出处:网络
Hai, I have a php project , which contain a form named contact us , In this when a user submit that form a mail has sent to the administrator.. My aim is to design this page as dynamic. I mean ,th开发

Hai,

I have a php project , which contain a form named contact us , In this when a user submit that form a mail has sent to the administrator.. My aim is to design this page as dynamic. I mean ,th开发者_如何学运维e admin can add or change the fields in contact us page. I have implemented a text editor to do this. here the admin can design the contact page. My problem is that i want to validate(both server side and client side) all the fields. how is it possible using javascript.. Does any one Know this ?


In order to make the validation work, you must have a set of predefined fields that can be added to the form.

I my last project, I do the same. There are service form that will be filled by visitor. The service owner can add the custom field in the application control panel, then the visitor will see the field. When designing, there are limited field type that can be added, a normal field: text, textarea, radio, checkbox, dropdown, and special field such as email address. The only validation needed is just required or not, and the special field will carry it's own validation rules along. This custom field data then saved to database.

When displaying this custom field, I use jQuery validation plugins to do in browser validation, while in backend code I also do validation using Form Validation library (I'm using CodeIgniter). All needed rules is carried by the custom field when fetching it from database.

I hope this is what you want to do. You might see wufoo.com to see what a field designer page will looks like. In my project, it's just a simple click and add, no drag and drop functionality. All code using jQuery, written by me for the project usage.


The form validation may not be possible without knowing what type of data is expected in a particular field. For example there may be multiple email field but unless the system knows that it is an email filed validation cannot be performed for emails. So the best way according to me is to setup the "text editor" or the form editor in such a way that a predefined field type can be assigned. For eg:

 $Field_1 = array(type=>"textbox",validate_as=>"email");


Perhaps you're saving the fields in a format that allows to identify the content type of each one. In that case, in the HTML you can ad an attribute to identify the validation type you'll need to apply in each case. You can then use some validation plugin. ( Java script coder validation script , LS Form validator for example)

Server side will be no different situation, perhaps even simpler.

0

精彩评论

暂无评论...
验证码 换一张
取 消