2

TOSを受け入れるためのチェックボックスを備えたフォームがあります。問題は、このチェックボックスにカスタム エラーを追加する必要があることです。

    <form>

    <input type="text" name="fname" placeholder="Name" /><?php echo form_error('fname') ?>
    <input type="text" name="email" placeholder="Email" /><?php echo form_error('email') ?>
    <input type="text" name="password" placeholder="Password" /><?php echo form_error('password') ?>

    <input type="checkbox" name="accept_terms" value="yes" /> Accept TOS<br>
    <?php echo form_error('accept_terms') ?>

    </form>

PHP

<?php 

 $this->form_validation->set_rules('fname','First Name','trim|required|xss_clean');
 $this->form_validation->set_rules('email','Email','trim|required|xss_clean|valid_email');
 $this->form_validation->set_rules('password','Password','trim|required|xss_clean');
 $this->form_validation->set_rules('accept_terms','TOS','trim|required|xss_clean'); // Need to add custom error message 

if ( $this->form_validation->run() === TRUE ) {

}else{

}
?>

ユーザーがTOSを選択しない場合、私は言わなければなりません

利用規約を読んで同意してください。

form_error注:個々のエラーを表示する機能を追加しました

4

2 に答える 2