2 つの入力フィールドのうち 1 つを正しく入力する必要がある場合。フォームのみが送信され、それ以外の場合はエラーが表示されます。codeigniterのクラスの関数を使用してそれを行うにはどうすればよいですか。set_rule
form_validation
1 に答える
1
(この例の目的のために)電子メールアドレスまたは電話番号のいずれかを検証したいとしましょう。次に、最も単純な形式で...
// If no email address, phone is required
if ( ! $this->input->post('email')) {
$this->form_validation->set_rules('phone', 'Phone Number', 'trim|numeric|min_length[11]|required');
} else {
$this->form_validation->set_rules('phone', 'Phone Number', 'trim|numeric|min_length[11]');
}
// If no phone number, email is required
if ( ! $this->input->post('phone')) {
$this->form_validation->set_rules('email', 'Email Address', 'trim|valid_email|required');
} else {
$this->form_validation->set_rules('email', 'Email Address', 'trim|valid_email');
}
...おそらく少し片付けることができますが、それはあなたが得ようとしていると私が思う一般的な考えです.
それが役に立てば幸い!!
于 2013-09-09T09:00:01.747 に答える