我有一个代码,我想在 Facebook 返回用户详细信息后 5 秒自动提交。但是代码无法自动提交。我找不到错误。我的代码如下所示
<?php
//some php functions to process the submitted form
?>
<div>
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: 'xxxxxxxxxxxxxxxx', status: true, cookie: true, xfbml: true});
/* All the events registered */
FB.Event.subscribe('auth.login', function(response) {
login();
});
FB.Event.subscribe('auth.logout', function(response) {
logout();
});
FB.getLoginStatus(function(response) {
if (response.session) {
login();
}
});
FB.getLoginStatus(function(response) {
login();
logout();
});
};
(function() {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
function login(){
FB.api('/me',function(response) {
if(typeof response.name != 'undefined')
{
document.getElementById('hideDiv').style.visibility = 'hidden';
document.signupForm.first_name.value=response.first_name;
document.signupForm.last_name.value=response.last_name;
document.signupForm.username.value=response.username;
document.signupForm.email.value=response.email;
}
});
}
function logout(){
//document.getElementById('login').style.display = "none";
}
setTimeout("document.signupForm.submit();",5000); //5 seconds
</script>
<form id="signupForm" name="signupForm" class="phorm2" action="" method="post">
<h3>Sign up</h3>
<div id="hideDiv">Get details from Facebook
<fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream"></fb:login-button>
</div>
<br>
<label class="short" for="first_name">First Name</label>
<input type="text" name="first_name" id="first_name" />
<br>
<label class="short" for="last_name">Last Name</label>
<input type="text" name="last_name" id="last_name" />
<br>
<label class="short" for="username">Username</label>
<input type="text" name="username" id="username" />
<br>
<label class="short" for="email">Email</label>
<input type="text" name="email" id="email"/>
<br>
<label class="short" for="submit"> </label>
<input type="submit" name="submit" value="Sign me up" class="Cart66ButtonPrimary" />
</form>
</div>