Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Facebook Connect提交表单并将Facebook电子邮件保存到db_Javascript_Php_Jquery_Facebook_Forms - Fatal编程技术网

Javascript Facebook Connect提交表单并将Facebook电子邮件保存到db

Javascript Facebook Connect提交表单并将Facebook电子邮件保存到db,javascript,php,jquery,facebook,forms,Javascript,Php,Jquery,Facebook,Forms,我有一个多步骤的表单,访问者可以填写,即使他们没有登录。但是,在表格的最后一部分,他们将被要求登录。当他们登录时,表单也会提交并保存到数据库中。我需要为Facebook登录/连接添加另一个按钮,该按钮也可以使用。我已经在我的顶部菜单使用PHP登录Facebook,用户可以登录那里,他们的电子邮件,名称将保存到我的用户表。表单的提交函数是JS格式的。我尝试过Ajax,但似乎不起作用 以下是表单代码的完整副本: Multistepform.html <!doctype HTML> <

我有一个多步骤的表单,访问者可以填写,即使他们没有登录。但是,在表格的最后一部分,他们将被要求登录。当他们登录时,表单也会提交并保存到数据库中。我需要为Facebook登录/连接添加另一个按钮,该按钮也可以使用。我已经在我的顶部菜单使用PHP登录Facebook,用户可以登录那里,他们的电子邮件,名称将保存到我的用户表。表单的提交函数是JS格式的。我尝试过Ajax,但似乎不起作用

以下是表单代码的完整副本:

Multistepform.html

<!doctype HTML>
<html>
<head>
<!-- jQuery easing plugin -->
<script src="http://sandbox.lookingfour.com/forms/multistepform/jquery.easing.min.js" type="text/javascript"></script>
<script src="http://sandbox.lookingfour.com/forms/multistepform/script.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="http://sandbox.lookingfour.com/forms/multistepform/style.css">
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-70871356-1', 'auto');
  ga('send', 'pageview');

</script>
</head>
<body>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '1378642095793539', // Set YOUR APP ID
      channelUrl : 'http://hayageek.com/examples/oauth/facebook/oauth-javascript/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    FB.Event.subscribe('auth.authResponseChange', function(response) 
    {
     if (response.status === 'connected') 
    {
        alert('connected');
        return false;
        //SUCCESS

    }    
    else if (response.status === 'not_authorized') 
    {
        alert('Not Authorized');

        //FAILED
    } else 
    {
        alert('LoggedOut');

        //UNKNOWN ERROR
    }
    }); 

    };

    function Login()
    {

        FB.login(function(response) {
           if (response.authResponse) 
           {
                buyerform_post();
            } else 
            {
             console.log('User cancelled login or did not fully authorize.');
            }
         },{scope: 'email,public_profile'});

    }

    }
    function Logout()
    {
        FB.logout(function(){document.location.reload();});
    }

  // Load the SDK asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));

</script>
<table>
  <tr class='popupbox-header'>      
    <td>
      <span id='buytitle'></span>
      <a href='' onclick='buyform_back(); return false;'>x</a>
    </td>
  </tr>
<!-- multistep form -->
<tr>
<td>
<div id="msform">
  <!-- progressbar -->
  <ul id="progressbar">
    <li class="active">Account Setup</li>
    <li>Social Profiles</li>
    <li>Personal Details</li>
  </ul>
  <!-- fieldsets -->
    <fieldset>
    <h2 class="fs-title">First Step</h2>
    <h3 class="fs-subtitle">This is step 1</h3>
    <label>Quantity</label>
    <?php echo input_textbox('buyqty', 1, "class='numeric'",'number'); ?><span class="formdata-required">*</span><br>
    <label>Condition </label>
    <select id = 'buycondition'>
      <option value = "New">New</option>
      <option value = "Used">Used</option>
    </select><br>
      <table>
      <tr>
      <td id='buyerexamples' ></td></br>
      </tr>
      </table>
    <input type="button" name="next" class="next action-button" value="Next" />
  </fieldset>
  <fieldset>
    <h2 class="fs-title">Second Step</h2>
    <h3 class="fs-subtitle">This is step 2</h3>
    <label>Deadline</label>
    <?php echo input_datebox('buydeadline', date('m/d/Y', strtotime("+7 days")), 1); ?>
    <span class="formdata-required">*</span><br>
    <label>Notes / Message</label>
    <textarea id='buynotes' style='width: 70%; height:90px;'></textarea>
    <input type="button" name="previous" class="previous action-button" value="Previous" />
    <input type="button" name="next" class="next action-button" value="Next" />
  </fieldset>
  <fieldset>

    <h2 class="fs-title">Third Step</h2>
    <h3 class="fs-subtitle">This is step 3</h3>
    <label>Location/Area</label>
              <select id = 'buylocation'>
                <option value = "Metro Manila">Metro Manila</option>
                <option value = "Abra">Abra</option>
              </select>
              <span class="formdata-required">*</span><br>
              <label>Budget</label>
              <?php echo input_textbox('buybudget','','placeholder="i.e. 5000 or 3500" style="width: 65%;"', '','text'); ?><br>
      <input type="button" name="previous" class="previous action-button" value="Previous" />
            <?php
              if (util_getuserid() == 0) {
                echo input_button('Look for Suppliers', 'buyform_showlogin();', 'id="buystartloginbtn" class="popup-button" style="background-color: #ea6e38;"');
                echo input_button('Sign-In', 'buyform_login("buyuser_login","buyuser_password","buyloginmsg");', 'id="buyloginbtn"  class="popup-button" style="background-color: #ea6e38;"');
              } else {
                echo input_button('Look for Suppliers', 'buyerform_post();', ' class="popup-button" style="background-color: #ea6e38;"');
              }
            ?>
  </fieldset>
</div>
<div class='menu-loginform' id='buyloginform' style="display:none;">
        <table width=100%>
          <tr>
            <td>
              <label style='text-align: left;'>Sign-In to proceed</label>
            </td>
          </tr>
          <tr>
            <td>
              <label style='text-align: left;'>Username / e-mail</label>
              <?php echo input_textbox('buyuser_login', '', 'class="popup-inputbox"', 'buyloginbtn'); ?>
            </td>
          </tr>
          <tr>
            <td>
              <label style='text-align: left;'>Password</label>
              <?php echo input_textbox('buyuser_password', '', 'class="popup-inputbox"', 'buyloginbtn','password'); ?>
              <a href='' OnClick='user_createtoplogin(); return false;' style='float: left;' id='buyform-createaccount'>Create a new account</a>
            </td>
          </tr>
          <tr>
            <td align=center>
              <div id='buyloginmsg' class="formdata-required" style="display:none;"></div>
            </td>
          </tr>
          <tr>
            <td>
            <?php
              if (util_getuserid() == 0) {
                echo input_button('Sign-In', 'buyform_login("buyuser_login","buyuser_password","buyloginmsg") && buyerform_post();', 'id="buyloginbtn"  class="popup-button" style="background-color: #ea6e38;"');
                echo input_button('Sign-In FB', 'Login()', 'id="status"  class="popup-button" style="background-color: #ea6e38;"');
              } else {
                echo input_button('Look for Suppliers', 'buyerform_post();', ' class="popup-button" style="background-color: #ea6e38;"');
              }
            ?>
            </td>
        </tr>
        </table>
      </div>
</td>
</tr>
</table>
</body>
</html>

(函数(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]| |函数(){
(i[r].q=i[r].q | |[]).push(参数)},i[r].l=1*新日期();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(窗口,文档,“脚本”,“www.google-analytics.com/analytics.js”,“ga”);
ga(“创建”、“UA-70871356-1”、“自动”);
ga(‘发送’、‘页面浏览’);
window.fbAsyninit=函数(){
FB.init({
appId:'1378642095793539',//设置你的应用ID
频道URL:'http://hayageek.com/examples/oauth/facebook/oauth-javascript/channel.html“,//通道文件
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true//解析xfbml
});
FB.Event.subscribe('auth.authResponseChange',函数(响应)
{
如果(response.status===“已连接”)
{
警报(“已连接”);
返回false;
//成功
}    
else if(response.status===“未授权”)
{
警报(“未授权”);
//失败
}否则
{
警报(“LoggedOut”);
//未知错误
}
}); 
};
函数登录()
{
FB.登录(功能(响应){
if(response.authResponse)
{
buyermer_post();
}否则
{
log('用户取消登录或未完全授权');
}
},{范围:'电子邮件,公共档案'});
}
}
函数注销()
{
注销(函数(){document.location.reload();});
}
//异步加载SDK
(职能(d){
var js,id='facebook jssdk',ref=d.getElementsByTagName('script')[0];
if(d.getElementById(id)){return;}
js=d.createElement('script');js.id=id;js.async=true;
js.src=“//connect.facebook.net/en_US/all.js”;
ref.parentNode.insertBefore(js,ref);
}(文件);
    帐户设置
  • 社会概况
  • 个人资料
第一步 这是第一步 量 *
条件 新的 使用

第二步 这是第二步 截止日期 *
注释/信息 第三步 这是第三步 地点/范围 大马尼拉 艾布拉 *
预算
我会尝试让他们先连接到FB,并将他们重定向到详细信息表单(尝试用FB的信息预先填充所有您可以的内容)。然后,提交的内容将像任何普通表单一样工作。但它实际上不是一个用于个人详细信息的表单
function buyerform_post()
{
    if(buyform_check() == false)
        return false;
    var param="";

    param = param + "buytitle="+datacheck_fixstring(document.getElementById('searchtext').value);
    param = param + "&buynotes="+datacheck_fixstring(document.getElementById('buynotes').value);
    param = param + "&buybudget="+datacheck_fixstring(document.getElementById('buybudget').value);
    param = param + "&buylocation="+datacheck_fixstring(document.getElementById('buylocation').value);
    param = param + "&buycondition="+datacheck_fixstring(document.getElementById('buycondition').value);
    param = param + "&buyqty="+datacheck_fixstring(document.getElementById('buyqty').value);
    param = param + "&buydeadline="+datacheck_fixdatetime(document.getElementById('buydeadline').value);


    // Examples
    var samplectr=0;
    var ctr = 0;
    var result = "";

    while (document.getElementById('check'+ctr)) {
        if (document.getElementById('check'+ctr).checked) {
            samplectr = samplectr+1;
            param = param + "&buysampletitle" + samplectr + "="+datacheck_fixstring(document.getElementById('sampletitle'+ctr).innerHTML);
            param = param + "&buysampleimgurl" + samplectr + "="+datacheck_fixstring(document.getElementById('sampleimgurl'+ctr).innerHTML);
            param = param + "&buysamplelink" + samplectr + "="+datacheck_fixstring(document.getElementById('samplelink'+ctr).innerHTML);
            param = param + "&buysampledesc" + samplectr + "="+datacheck_fixstring(document.getElementById('sampledescription'+ctr).innerHTML);
        }
        ctr = ctr + 1;
    }   
    param = param + "&buysamplectr="+samplectr;

    return ajax_postrequest("posts/post.php", param, "buyloginmsg", buyform_handlepostbuy);
}

function buyform_handlepostbuy(result, targetid)
{
    util_reload('posts/?member=0');
}

    function buyform_login(usernameid,userpasswordid,targetid)
{
    var username = document.getElementById(usernameid).value;
    var userpassword = document.getElementById(userpasswordid).value;

    if (username.length < 1) {
        util_alertmsg("Please indicate login");
        return false;
    }
    if (userpassword.length < 1) {
        util_alertmsg("Please indicate password");
        return false;
    }

    document.getElementById(targetid).innerHTML='';
    document.getElementById(targetid).style.display='';
    return ajax_getrequest("login.php", 'user_login='+username+'&user_password='+userpassword, targetid, buyform_handlelogin);

}


function buyform_handlelogin(result, targetid)
{
    if (result == "OK") {
        alert('hello');
        buyerform_post();
        window.location.reload();
        util_reload('');
    } else if (document.getElementById(targetid)) {
        document.getElementById(targetid).style.display='';
        ajax_genericget(result, targetid);
    }
}