问题描述
这是一个很奇怪的问题,我似乎无法解决。在WordPress网站上,我通过短代码在网站上输出了多种表单(登录,注册和其他)。当提交表单时,他们的数据通过一个init钩子来处理,这个钩子监听$ _POST数据。
请注意,该网站正在运行WordPress,但我有这是为什么我在这里发布。
当在IE 9中提交表单时,所有字段的值都会被清除点击提交。例如,假设有一个名称为username的输入字段,并且该字段的值设置为johndoe;当通过除IE 9以外的任何浏览器提交表单(包括7和8)时,数据将如下所示:
$ _ POST ['username '] ='johndoe'
完全如预期。 然而,当这个表单是用IE9提交的,它是这样出现的:
$ _ POST ['username'] =''
据我所知,网站上的每个表单都会发生这种情况。
自定义登录例如,我创建的窗体如下所示:
< form id =re_login_formclass =re_login_form action =method =post>
< fieldset>
< label for =re_user_Login><?php _e('Username','re'); ?>< /标签>
< input name =re_user_loginid =re_user_loginclass =requiredtype =texttitle =<?php _e('Username','re');?>/ >
< / fieldset>
< fieldset>
< label for =re_user_pass><?php _e('Password','re'); ?>< /标签>
< input name =re_user_passid =re_user_passclass =password requiredtype =password/>
< / fieldset>
< fieldset class =form-action>
< input type =hiddenname =refalf_redirectvalue =<?php echo $ redirect;?>/>
< input type =hiddenname =re_login_noncevalue =<?php echo wp_create_nonce('re-login-nonce');?>/>
< input id =re_login_submittype =submitclass =button re_submitvalue =<?php _e('Log In','re');?>/>
< p class =忘记密码>< a href =<?php echo wp_lostpassword_url(get_permalink());?> title =<?php _e('Lost Password','re');?>><?php _e('Lost Password?','re'); ?>< / A>< / p为H.
< / fieldset>
< / form>
其中一件更有趣的事情是,点击提交时,这些字段明显清除了它们的值在IE9中。也就好像提交按钮在IE9中触发了一些清除字段的东西。
任何人有任何想法?
我可以通过给每个输入字段一个占位符属性来解决这个问题。我仍然不知道为什么它能起作用,但是当占位符出现时,一切正常。
This is a really strange issue that I cannot seem to solve. On a WordPress site, I have several forms (login, registration, and other) outputted on a site via short codes. When the forms are submitted, their data is processed via an "init" hook that listens for the $_POST data.
Note, the site is running WordPress, but I have deemed this to not be a WordPress issue, which is why I'm posting here.
When the forms are submitted in IE 9, all fields are cleared of the values when clicking submit. For example, let's say there is an input field with a name of "username", and the field's value is set to "johndoe"; when submitting the form through any browser besides IE 9 (include 7 and 8), the data comes in like this:
$_POST['username'] = 'johndoe'
Exactly as expected.
However, when the form is submitted with IE9, it comes out like this:
$_POST['username'] = ''
As far as I can tell, it happens with every form on the site.
The custom login form I've built, for example, looks like this:
<form id="re_login_form" class="re_login_form" action="" method="post">
<fieldset>
<label for="re_user_Login"><?php _e('Username', 're'); ?></label>
<input name="re_user_login" id="re_user_login" class="required" type="text" title="<?php _e('Username', 're'); ?>"/>
</fieldset>
<fieldset>
<label for="re_user_pass"><?php _e('Password', 're'); ?></label>
<input name="re_user_pass" id="re_user_pass" class="password required" type="password"/>
</fieldset>
<fieldset class="form-action">
<input type="hidden" name="refalf_redirect" value="<?php echo $redirect; ?>"/>
<input type="hidden" name="re_login_nonce" value="<?php echo wp_create_nonce('re-login-nonce'); ?>"/>
<input id="re_login_submit" type="submit" class="button re_submit" value="<?php _e('Log In', 're'); ?>"/>
<p class="forgot-password"><a href="<?php echo wp_lostpassword_url( get_permalink() ); ?>" title="<?php _e('Lost Password', 're'); ?>"><?php _e('Lost Password?', 're'); ?></a></p>
</fieldset>
</form>
One of the things that is extra interesting is that the fields are visibly cleared of their values when clicking submit in IE9. It's also as though the submit button is triggering something in IE9 that clears the fields.
Anyone have any ideas?
I was able to solve this by giving each input field a placeholder attribute. I still don't know why that made it work, but when the placeholder was present, everything worked fine.
这篇关于IE 9清除表单域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!