2012-02-08 6 views
2

私のフォームがいつも検証に失敗するのか誰にも気付くことができますか? 検証でエラーは出力されず、POST配列は常に空です。 私には、間違った場所に提出されることを提案しますが、そうではありません。ここでCodeIgniterを使用した空のPOST結果form_validation

<form action="https://www.mydomain.com/account/withdraw" method="post" accept-charset="utf-8">  <fieldset class="six-col"> 
     <h3>What amount?</h3> 
     <span style="font-size:1.3em;position:relative;display:inline;">&pound;</span> 
     <input id="amount" type="text" placeholder="1.00" style="font-size:1.3em;width:115px;background-color: transparent;color:white;"/> 

    </fieldset> 
    <fieldset class="six-col"> 
     <h3>Charges</h3> 
     <span id="charges" style="font-size:1.3em;"></span> 
    </fieldset> 
    <fieldset class="six-col"> 
     <h3>You leave with</h3> 
     <span id="charges2" style="font-size:1.3em;"></span> 
    </fieldset> 
    <fieldset class="six-col end-col"> 
     <input type="submit" id="submit" class="btn" value="Withdraw" style="width:125px;position:absolute;bottom:0" /> 
    </fieldset> 
</form> 

は、コントローラは、あなたが入力に設定された名前を持っていない任意の助け

答えて

5

ため

$this->load->library('form_validation'); 

    $this->form_validation->set_rules('amount', 'Amount', 'required|xss_clean|trim|numeric|max_length[5]'); 

    if ($this->form_validation->run() == FALSE) 
    {   
     $this->load->helper(array('form', 'url')); 
     $data['credit'] = $this->account_m->get_credit(); 
     $this->load->view('account/withdraw', $data); 
    } 
    else 
    { 
     // The withdraw code 
    } 
    $this->load->view('footer'); 

おかげ..です それは次のようになります。<input name="amount" id="amount" type="text" placeholder="1.00" style="font-size:1.3em;width:115px;background-color: transparent;color:white;"/>

ていることを確認します実際に何かを取り戻しています。

で可能なすべてのテストをするかの..はそうのようなform_validation前にポストするvarをエコー:

<?php echo $this->input->post('amount'); ?> 

あなたが戻って、そのフォームを値を取得していない場合は、POST代わりのpostを使用してみてください。

値を取得している場合は、そのルール。 1つの可能性は、numericルールです。整数を試してください。 is_naturalを試すか、$ 0.00を使用している場合はdecimalを試してください。また

http://codeigniter.com/user_guide/general/profiling.html

<?php $this->output->enable_profiler(TRUE); ?> 
+2

...開発のための良いキャッチをCodeIgniterのプロファイラクラスを使用し、NAME' '欠けていることに気づきませんでした。 +1 – DaveRandom

+0

私はいつも何かしていますが、CIsプロファイラはGoogle Chromeデベロッパーツールキットを使ってXHRヘッダーを開発したり監視したりするのに最適なツールです。 – gorelative

+0

気楽な猶予期間!私はあなたが私の答えを投稿していた間にちょうどその部分(欠けている名前の部分)を追加しました:) +1とにかく –

関連する問題