开发者

How to ignore a default value using the CodeIgniter Validation Helper

I have validation on all areas of a form, and within the inputs I have hints which are set in the input's Value.

However, the problem I have is that CodeIgniter see's the input as being filled in so a Validation error doesn't occur.

I know I can create a callback_function for each input, but with around 10 forms and 100 inputs I was hoping to avoid this and possibly create a generic function or rule?

Any help is greatly appre开发者_运维问答ciated


You seem to be setting default values for your inputs when what you really want is a placeholder

So instead of this:

<input value="Enter your email" />

You want this:

<input placeholder="Enter your email" />

Depending on how you are setting up your input data, a single callback function could suffice if you really needed it, but really: Don't start hacking up Codeigniter for this. Just use placeholder as it was intended (see javascript solutions for older browsers).

Read more about it here:

http://diveintohtml5.ep.io/forms.html#placeholder


I am assuming what you mean is this:

Ghosted Values http://img864.imageshack.us/img864/8124/ghosted.png

Where the value in there is never meant to be the actual value?


The easy solution is to have a class on the <input> that indicates that it's using a stock input (and also it can grey the text out). When the user clicks in the field javascript can clear the initial value out for you (and remove the marker class).

You can then on the submit button click event go through the form and clear the values of anything with the marker class before you actually submit the form.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜