0

我有一个表单,我想使用 jQuery 来更改它的操作并将其发布到另一个 php。

这就是我所做的......它一直告诉我我没有发布任何东西......我确实提交了表格并发布了它。

我的脚本:

<script>
function facebook(){
$("#first-form").attr("action", "/yiiauth/default/authenticatewithfacebook");
$('#first-form').submit();
}

function gmail(){
$("#first-form").attr("action", "/yiiauth/default/authenticatewithgoogle");
$('#first-form').submit();
}
</script>

我的 php 来处理这个表单:

    public function actionAuthenticatewithfacebook($provider="facebook") {

        $hybridauth_config =Yiiauth::hybridAuthConfig();

        $error = false;
        $user_profile = false;
        try{
        // create an instance for Hybridauth with the configuration file path as parameter
            $hybridauth = new Hybrid_Auth( $hybridauth_config );

            $adapter = $hybridauth->authenticate( $provider );
            $user_profile = $adapter->getUserProfile();

        }
        catch( Exception $e ){
            // Display the recived error
            switch( $e->getCode() ){ 
                case 0 : $error = "Unspecified error."; break;
                case 1 : $error = "Hybriauth configuration error."; break;
                case 2 : $error = "Provider not properly configured."; break;
                case 3 : $error = "Unknown or disabled provider."; break;
                case 4 : $error = "Missing provider application credentials."; break;
                case 5 : $error = "Authentification failed. The user has canceled the authentication or the provider refused the connection."; break;
                case 6 : $error = "User profile request failed. Most likely the user is not connected to the provider and he should to authenticate again."; 
                         $adapter->logout(); 
                         break;
                case 7 : $error = "User not connected to the provider."; 
                         $adapter->logout(); 
                         break;
            } 


        }

        // workOnUser returns an user object
        if ( is_object ($user_profile) ){
        $user = $this->workOnUser($provider,$user_profile->identifier); 
            if ( $this->autoLogin($user) ){

if (Yii::app()->user->returnUrl === Yii::app()->request->scriptUrl)
                {
                        if (isset($_SERVER['HTTP_REFERER']))
                        {
                                Yii::app()->user->setReturnUrl($_SERVER['HTTP_REFERER']);
                        }
                }
else{
Yii::app()->user->setReturnUrl('');
}

       if(isset($_POST['Prequestions'])|| isset($_POST['Prequestions[name]']))
       {
       $questions = new Questions;
       $questions->attributes=$_POST['Prequestions'];
       $questions->save();

       }else{
       throw new CHttpException(404,"Whoops, sorry we can't find the page you requested.");
}

$returnUrl = Yii::app()->user->returnUrl;
Hybrid_Auth::redirect($returnUrl);  

                }else{
                    // this is where u go otherwise
                    $this->render('authenticatewith',array('error'=>$error,'user_profile'=>$user_profile ) );
                    }
            }else{
                    echo "Something wrong with ".$provider;
                }
}

这是我表格中的一个示例....

<label for="Prequestions_name">Title</label>
<input id="title" type="text" value="" name="Prequestions[name]" style="width:420px;" maxlength="256" size="256">

....现在它确实重定向到我的 actionAuthenticatewithfacebook,但没有向它发布任何内容....

4

0 回答 0