私は自分のフォームに、組織名、部門名、位置、期間として入力された作業経験があります。codeigniterで配列の値を検証する方法
<tr>
<td><span class="serial_no">1</span></td>
<td><input type="text" name="organization[]" size="50"/></td>
<td><input type="text" name="department[]" size="50"></td>
<td><input type="text" name="positions[]" size="40"></td>
<td><input type="text" name="duration[]"></td>
</tr>
私は以下のなかったCIで検証中:
$organization = $this->input->post('organization');
$department = $this->input->post('department');
$positions = $this->input->post('positions');
$duration = $this->input->post('duration');
//printr($organization);
for($i = 0; $i < count($organization); $i++)
{
$org = $organization[$i];
$dept = $department[$i];
$pos = $positions[$i];
$dura = $duration[$i];
$this->form_validation->set_rules($org, "Organization", "trim|xss_clean|max_length[1]");
$this->form_validation->set_rules($dept, "Department", "trim|xss_clean|max_length[50]");
$this->form_validation->set_rules($pos, "Position", "trim|xss_clean|max_length[40]");
$this->form_validation->set_rules($dura, "Duration", "trim|xss_clean|integer");
}
としてエラーが表示される:今の問題は、それは整数として期間を検証しないで
<?php
echo form_error("organization[]");
echo form_error("department[]");
echo form_error("positions[]");
echo form_error("duration[]");
?>
。ランダムなアルファベットを入力しても、エラーは表示されません。
私は次のように検証
は:$this->form_validation->set_rules('organization[]', "Organization", "trim|xss_clean|max_length[50]");
$this->form_validation->set_rules('department[]', "Department", "trim|xss_clean|max_length[50]");
$this->form_validation->set_rules('positions[]', "Position", "trim|xss_clean|max_length[40]");
$this->form_validation->set_rules('duration[]',"Duration", "trim|xss_clean|numeric");
それはそれがされていないとして必須の期間がかかるとして私がフォームを送信することはできません。
どうすれば解決できますか?
助けを歓迎します。ありがとう。
をshouldn次のように私の誤りを表示; tは 'duration'検証に(あまりと' xss_clean') 'trim'を追加しますか? –
@サミー私は私の答えを更新しました。リンクが追加されていることを確認してください。いかなるフィードバックも歓迎されます。 –