0

I have been on this site all day and can't seem to find what I need - no duplicate post intended.

I have a form containing a link which calls a modal popup containing a different form.

###### PARENT PAGE #############
<form...>
...
<a href="php_page.php?id=<?php echo $id; ?>&sect=<?php echo $sect; ?>">link</a>
...
</form>

**** MODAL POPUP ****
<form...>
...
<input type="submit" />
</form>
**** END MODAL POPUP ****

### END PARENT PAGE #############

When I submit the form in the modal popup, the parent page is refreshed to show the updated info in the corresponding section of the page; except that the first form is not submitted and when the page refreshes to update the necessary section, the contents of the first form is lost.

I have tried using ajax to refresh only the necessary section of the page but that doesn't work as the sections that need refreshing use php variables with contents from mysql.

The system does what it needs to do and I don't mind the refresh. But I need a way to keep the user data entered into the first form.

Is it possible to submit the first form at the same time as the second to the same php page or any other way of preserving the user data in the first form on page reload without submitting it.

4

2 に答える 2

1

純粋なphpではこれを行うことはできません。JavaScript が必要で、モーダルで送信を押したときに情報を親フォームに戻すように記述します。

1 つの方法は、モーダル フォームの送信ボタンを実際の送信ボタンではなくすることです。

親フォームに注入されたモーダルで記入済みの section dom 要素を取り出すことで、うまくいくことさえあるかもしれません。一部の jquery プラグインはすでにこれを行っています。たとえば、 カラーボックス

<form>これは、1 つのタグと jquery カラーボックスのみを使用した実際の例です。http://jsbin.com/olalam/1/edit

于 2012-12-11T18:12:01.467 に答える
0

私は PHP 開発者ではないので、別の方法を提案します。

ページを更新する前に、フォームをシリアル化し、データをローカルに (Cookie などに) 保存してから、データをフォームに戻すことができます。確かに、それにはもう少し JS コードが必要ですが、必要なものは得られるはずです。

更新: JS フロントで少し支援が必要かもしれないと述べたので、ここにいくつかのガイダンスがあります。

  1. ここjquery.cookieプラグインを入手してください。
  2. ここjquery.deserializeプラグインを入手してください。
  3. 次のコードを出発点として使用します。

.

// the name of the cookie
var cookieName = 'myCookieName';

function beforeSubmit() {
    // serialize the form into a variable
    var serializedForm = $('#id-of-form').serialize();
    // store the serialized form
    $.cookie(cookieName, serializedForm, { path: '/' });
}

function afterRefresh() {
    // read the cookie
    var serializedForm = $.cookie(cookieName);
    // de-serialize the form
    $('#id-of-form').deserialize(serializedForm, true);
}

HTH

于 2012-12-11T17:57:34.893 に答える