0

cgimail を使用して基本的な HTML コンタクト フォームを作成しましたが、すべてが機能しますが、フォームが送信された後にどこかにリダイレクトされないようにすることはできません。代わりに、ページの上部にあるブートストラップ アラートを使用しようとしています。

フォームを送信して、リダイレクトしないようにするにはどうすればよいですか?

コードは次のとおりです。

      <form method="post" action="/cgi-bin/cgiemail/forms/email.txt">
        <fieldset>
          <h2 id="contact-header">Contact</h2>
          <label>Name:</label>
          <input type="text" name="yourname" placeholder="" autofocus>
          <label>Email Address:</label>
          <input type="email" name="email" value="" placeholder="">
          <label>Phone:</label>
          <input type="tel" name="phone" value="" placeholder="">
          <label>Message:</label>
          <textarea name="message" rows="2"></textarea>
          <br>
          <button type="submit" id="formSubmit" class="btn">Send</button>
          <input type="hidden" name="success" value="">
        </fieldset>
      </form>

ありがとう、ライアン

4

3 に答える 3

1

2 つの簡単な選択肢があります。jQuery とそのフォーム プラグインを使用して、これを ajax 操作に変換するか、独自の同等のものをロールすることができます。次のようになります (jQuery を使用)。

$('form').submit(function() {
  ... get all values.
  ... ajax post the values to the server.
  return false;
});
于 2013-07-31T20:31:25.743 に答える
0

jQuery を使用している場合は、submitイベントをキャンセルしてみてください。最初にフォームにid

HTML:

<form id="myform" ...

JavaScript:

$('#myform').on('submit', function(e) {
    e.preventDefault();

    $.ajax({
        url: '/cgi-bin/cgiemail/forms/email.txt',
        type: 'post',
        data: $(this).serialize()
    });

    return false;
});
于 2013-07-31T20:30:54.057 に答える