开发者

jQuery hint plugin and problem with $_POST

开发者 https://www.devze.com 2023-03-18 07:07 出处:网络
I\'m using remy sharp\'s hint plugin. <input type=\"text\" title=\"hint\" name=\"names\" class=\"input\" />

I'm using remy sharp's hint plugin.

<input type="text" title="hint" name="names" class="input" />

But when I post the form without filling the fields, input stil开发者_JAVA技巧l has

  $_POST['names'] = 'hint';

How can I prevent this issue?

Thanks in advance.

EDIT : jQuery Code:

$(".input").hint();

$(".lSubmit").click(function(e){
   e.preventDefault();
   $.post('form.php',decodeURIComponent($("#forms").serialize()) , function(data) {
   $('.result').html(data);
     });
 });


The plugin removes the hint itself when the form the input is in gets submitted, unfortunately you are not submitting the form, but posting it via $.post.

The most simple way would probably to check the value(s) of the input(s) just before it gets submitted against its title, and clear it if they are the same:

$(".lSubmit").click(function(e){

   // clear inputs that still have the hint as value
   $('.input').each(function() {
      if($(this).val() == $(this).attr('title')) {
         $(this).val("");
      }
   });

   e.preventDefault();
   $.post('form.php',decodeURIComponent($("#forms").serialize()) , function(data) {
   $('.result').html(data);
     });
 });


You cant.

Just add an if statement to your code:

if($_POST['names'] == 'hint' ) {
   //DONT USE IT!!
}
0

精彩评论

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