2017-03-11 19 views
-1

申し訳ありませんが、私は小さなシステムを作成しており、顧客はオンラインで注文することができます。注文を電子メールで受け取り、私たち自身のシステムで処理します。彼らは記入する必要があるいくつかの基本的な情報と、ページに注文を配置します。その後、彼らは彼らの注文を記入する必要があります。各注文行には3つのフィールドがあります。部品番号、数量および価格。価格は読み取り専用になり、提出されることはありません。価格を表示するだけです。複数の未定義数量入力

小さな入力フィールドとプラスアイコンをjQueryで作成したいと考えています。 10を入力してプラスアイコンをクリックすると、3つのフィールドの10行が追加されます。これは私がまだ作成したものではありませんでしたが、今はどのようにして仕事をしたいのか分かります。

問題はどうやってフォームを処理するのですか?フィールドは必須ですが、行が空の場合はPHPで送信または無視されません。だから私は記入されているフォームをチェックしたいだけです。時々それは4行、時には20、時には100行になります。だから私たちは知らない入力の量。フォーム名はどのように作成すればよいですか?ここで

いくつかのPHP:

if(toxInput::exists()){ 

場合(toxToken ::チェック(toxInput ::( 'トークン' を取得))){

$toxValidate = new toxValidate(); 
$toxValidation = $toxValidate->check('$_POST', array(
     'po'   => array('required' => TRUE), 
     'date'  => array('required' => TRUE), 
     'bo'   => array('required' => TRUE), 
     'remarks' => array('required' => TRUE) 
)); 

if($toxValidate->passed()){ 
    echo 'Run insert'; 
} 

}}

ここどのように見えるフォームのスクリーンショット:http://prntscr.com/eigfc2

ここでの形式のHTML:

<p><h2>Items</h2></p> 
         <p class="order"> 
         <label style="margin-left:20px;">Partnumber:</label><br /> 
         <input type="text" style="margin-left:20px;" class="text medium" placeholder="SP partnumber" /> 
         </p> 
         <p class="order" > 
         <label style="margin-left:20px">Qty</label><br> 
         <input type="text" id="qty" name="qty" style="margin-left:20px;" class="text small" placeholder="Qty" /> 
         <p class="order"> 
         <label style="margin-left:20px">Price</label><br> 
         <input type="text" style="margin-left:20px;" class="text small" placeholder="Price" readonly /><br> 
         </p> 
        <p> 
        <input type="text" style="margin-left:20px;" class="text medium" placeholder="SP partnumber" /> 
        <input type="text" style="margin-left:16px;" class="text small" placeholder="Qty" /> 
        <input type="text" style="margin-left:16px;" class="text small" placeholder="Price" readonly /> 
        </p> 
        <p> 
        <input type="text" style="margin-left:20px;" class="text medium" placeholder="SP partnumber" /> 
        <input type="text" style="margin-left:16px;" class="text small" placeholder="Qty" /> 
        <input type="text" style="margin-left:16px;" class="text small" placeholder="Price" readonly /> 
        </p> 
        <p> 
        <input type="text" style="margin-left:20px;" class="text medium" placeholder="SP partnumber" /> 
        <input type="text" style="margin-left:16px;" class="text small" placeholder="Qty" /> 
        <input type="text" style="margin-left:16px;" class="text small" placeholder="Price" readonly /> 
        </p> 
        <p> 
        <input type="text" style="margin-left:20px;" class="text medium" placeholder="SP partnumber" /> 
        <input type="text" style="margin-left:16px;" class="text small" placeholder="Qty" /> 
        <input type="text" style="margin-left:16px;" class="text small" placeholder="Price" readonly /> 
        </p> 
        <p> 
        <input type="text" style="margin-left:20px;" class="text medium" placeholder="SP partnumber" /> 
        <input type="text" style="margin-left:16px;" class="text small" placeholder="Qty" /> 
        <input type="text" style="margin-left:16px;" class="text small" placeholder="Price" readonly /> 
        </p> 
        <p> 
        <input type="text" style="margin-left:20px;" class="text medium" placeholder="SP partnumber" /> 
        <input type="text" style="margin-left:16px;" class="text small" placeholder="Qty" /> 
        <input type="text" style="margin-left:16px;" class="text small" placeholder="Price" readonly /> 
        </p> 

        <input type="hidden" name="token" value="<?php echo toxToken::generate(); ?>"> 

私はマージンについて知っていますが、クラスでうまくいく必要がありますが、テスト用です。

+0

* *「どのように私は、フォーム名を作成する必要がありますか?」 - 入力フィールド名はすべて同じであること、およびPHPの配列として扱わなければなりません側。 (つまり、すべてのPart Numberフィールドは互いに同じ名前を持ち、Quantityフィールドはすべて同じ名前でなければなりません)私はPHPの人ではありませんが、 PHPで動作する 'Qty []'のような名前ですか?空行を無視する1つの方法は、jQueryを使用して行をループし、それらを削除するか、 'name'属性を削除して提出しないようにすることです。しかし、あなたはどちらの方法でもPHP側のデータを検証する必要があります。 – nnnnnn

答えて

1

私はこれを書いて、入力フィールドを追加する方法を示しました。これは配列を使用します。私は1つの入力変数(myOrder)だけを使用していますが、あなたが望むだけ多くを使用することができます。 forループでより簡単に検証できます。

<html> 
<head> 
<script> 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"> 
</script> 
<script> 
$(document).ready(function(){ 
    $("#myButton").click(function(){ 
     // create loop to add ten inputs if needed 
     $("#myOrderForm").append('Product: <input type="text" 
       name="myOrder[]" /><br>'); 
     }); 
    }); 
</script> 
</head> 
<body> 
<input id="myButton" type="button" value="Buy another product" /> 

<form method="post" action="addInput.php"> 
<div id="myOrderForm"> //input tags here 
Product: <input type="text" name="myOrder[]" /><br> 
Product: <input type="text" name="myOrder[]" /><br> 
</div> 
<input type="submit" value="Place Order"> 
</form> 
</body> 
</html> 

PHPファイルaddInput.php

<?php 
$myOrders=$_POST["myOrder"]; 
for ($i=0; $i<count($myOrders); $i++) 
    { 
    // validate each array member with if (empty($myOrders[$i])) 
    // do something 
    echo $myOrders[$i]."<br>"; // echo just for example 
    } 

?>