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