HTTP_REFERER を使用する代わりに、この無料のアドオンhttp://devot-ee.com/add-ons/page-historyを使用して、最後にアクセスしたページ (または前から最後まで) を取得します。
フォームの一部 (RET の非表示フィールド) として設定するか、フォームの送信を制御する JavaScript (またはフォームの送信先のページ) に出力します。
<input type="hidden" value="{exp:page_history:get page=‘1’}" name="RET"/>
結果ページに、iFrame を使用せずに同じページにリダイレクトする Jquery を含めることができます。
if (top.location.href != document.location.href) {
//### Inside an iFrame ###
if (document.location.href.indexOf("/redirected page after login") >= 0) {
//### Breakout of iFrame ###
$("body").css("display","none"); //Hide to minimise 'flicker'
top.location.href = document.location.href;
}
}
または、JavaScript でログイン フォームの送信をトラップし、Ajax 経由でページを送信してから、選択した URL にリダイレクトします (ファンシー ボックスを閉じる必要はなく、 target top.location.href
.
以下は、Ajax 経由でサーバー エラー チェック応答を含むログイン フォームを送信する JQuery の例です。
//### LOGIN FORM SUBMISSION ###
function SubmitLogin() {
//### Send form via AJAX ###
$.ajax({
type: "POST",
data: $("#login-form").serialize() + "&action=" + $("#login-form").attr("action"),
dataType: "html",
success: function (html) {
//### Successfully received an html page from the server ###
if ( html.search(/error/i) >= 0 ) {
if (html.search(/username you submitted was not found/i) >= 0) {
$("#login-username").addClass('error');
$("#login-username").after('<label class="error" for="login-username" generated="true">Email address doesn\'t exist<br />Re-check or register an account</label>');
} else if (html.toLowerCase().indexOf("account does not exist") != -1) {
//Do appropriate selection & error message
} else if (html.search(/You did not submit a valid email address/i) >= 0) {
//Do appropriate selection & error message
} else if (html.search(/captcha/i) >= 0) {
$("#captcha").addClass('error').after('<label class="error" generated="true">' + $("#captcha").attr('title') + '</label>')
} else if (html.search(/password/i) >= 0) {
$("#login-password").addClass('error');
$("#login-password").after('<label class="error" for="login-username" generated="true">You have entered an incorrect password</label>');
} else if (html.search(/already logged in/i) >= 0) {
$("#login-butn").after('<label class="error" for="login-username" generated="true">User already logged in!</label>');
} else if (html.search(/account has not been activated yet/i) >= 0) {
$("#login-butn").after('<label class="error" for="login-username" generated="true">Account has not been activated yet<br />Check your email and activate</label>');
} else {
}
} else {
//### Successfully Logged in ###
top.location.href = "where ever you want to go";
// Target RET field of form here...?
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
//### Error occurred, could be server, CMS or 404 ###
}
});
} //### End of SubmitLogin function ###
これは、いくつかの EE1 エラー メッセージに基づいた例にすぎず、EE2 からのいくつかのエラー メッセージで更新したので、送信の Ajax ルートをたどってリダイレクトすることを選択した場合の出発点となるはずです。