1

送信ボタンが異なるページに 3 つのフォームがあり、すべての HTML が適切に閉じられています。すべてのフォームには異なる値があります..今の問題は、データベースに値を保存するために任意のフォームの送信ボタンを押すと..別のフォームフィールドが空になることです..どうすればそれらを停止させないようにできますか.送信ボタンを押したときに欲しい.任意のフォームのこれらのフォーム値のみがデータベースに送信されます..他のフォームフィールドは空になりません..どうすればこれを解決できますか..私はこのような単一のフォームのコーディングを行いました.

        <form class="form" method="POST" name="pool">
  <label for="name1">Ist Player Name</label>
 <input type="text" name="fname" id="fname"  />
    <label for="name2">2nd Player Name</label></td><td><input type="text" name="sname"    id="sname"   />
 <label for="stime">Start Time</label>
 <input type="text" name="stime" id="stime" 
      <label for="stime">End Time</label>
       input type="text" name="etime" id="etime" />
<input type="submit" value="Confirm" name="pool" id="pool"  />
 </form>

2番目と3番目のフォームと同じ.nameはすべてのフォームの変更です..そしてこのようなフォームのphpコーディング

   <?php
   $con = mysql_connect("localhost","root","");
    mysql_select_db("snookar", $con);

   if(isset($_POST['pool']))
   {
    /* all procees to save record */
   }
     then 2 nd form
     if(isset($_POST['snooke']))
   {
    /* all procees to save record */
   } and so on...

これで、指定されたフォーム値のみを送信し、別のフォームが空にならないのはどうすればよいですか...

4

2 に答える 2

0

ajax スクリプト。

$('input#form1button').click( function() {
$.ajax({
url: 'some-url',
type: 'post',
dataType: 'json',
data: $('form#myForm1').serialize(),
success: function(data) {
$("#myForm1").resetForm();
return false
}
});
});

上記のコードの form1button は、フォーム内のボタンの ID、つまり ID myForm1 のフォームである
ため、フォームとボタン ID が異なる残りの 2 つのフォームに対して同じ関数を繰り返します。

HTML

<form method='POST' aciton='' id='myForm1'>
some inputs goes here
<input type=button id=form1button />
</form>

于 2013-05-16T08:29:08.240 に答える
0

次のことができます。

<form class="form" method="POST" name="pool1">
     <!-- Form input fields -->
     <input type="submit" value="Confirm" name="poolbtn1" id="poolbtn1"  />
</form>

<form class="form" method="POST" name="pool2">
     <!-- Form input fields -->
     <input type="submit" value="Confirm" name="poolbtn2" id="poolbtn2"  />
</form>

を使用しjqueryてフォームを送信します。

$("#pool1").submit(function(e) {
   //Do your task here
   return false; //this will prevent your page from refreshing
}

$("#pool2").submit(function(e) {
   //Do your task here
   return false; //this will prevent your page from refreshing
}
于 2013-05-16T07:32:31.657 に答える