doujun1495 2016-08-09 08:16
浏览 25
已采纳

Codeigniter单选按钮不起作用[PHP,HTML]

I am creating test project with codeigniter and i am struggling with radio buttons and options. I would like to create advance question form with for example 6 different radio buttons selects and input labels such name, surname etc (which i successfully achieved)

When i fill necessary fields and set test radio button to proper value and hit submit button simply nothing happen and. I can't find what causes the problem.

I am using here form helper (that says documentation to use set_radio)

I tried to use form_radio, set_radio etc. You will find my examples below

Here is my view (i didn't paste text input because that part is working)

<div class="row">
    <?php
        $attributes = array(
            "name" => "registrationform",
            "id" => "msform"
            );
        echo form_open("yourself/register", $attributes);
    ?>
    <!-- progressbar -->
    <ul id="progressbar">
        <li class="active"><span class="circle">1</span> APPLY</li>
        <li class="active"><span class="circle">2</span> FORM</li>
        <li><span class="circle">3</span> CHECK</li>
    </ul>
    <!-- FORM Yourself -->
    <fieldset>

        <div class="input-box">
            <h2 class="title">What licence would you like?</h2>
            <input type="radio" name="what_licence" value="1" <?php echo  set_radio('what_licence', '1', TRUE); ?> /> Black and white?</label>
            <input type="radio" name="what_licence" value="2" <?php echo  set_radio('what_licence', '2'); ?> /> Colour?</label>
        </div>
        <div class="form-group">
            <button name="submit" type="submit" class="btn btn-default">Signup</button>
            <button name="cancel" type="reset" class="btn btn-default">Cancel</button>
        </div>

    </fieldset>
    <!-- FORM Yourself -->
    </form>
    <?php echo form_close(); ?>
    <?php echo $this->session->flashdata('msg'); ?>
</div>
<!-- row -->

Here is my controller

    $this->form_validation->set_rules('what_licence', 'What licence', 'required');
    $this->form_validation->set_rules('initials', 'Initials', 'trim|required|alpha');
    $this->form_validation->set_rules('lastname', 'Last Name', 'trim|required|alpha|min_length[3]|max_length[30]');
    $this->form_validation->set_rules('email', 'Email ID', 'trim|required|valid_email|is_unique[yourself.email]');
    $this->form_validation->set_rules('tel_number', 'Phone Number', 'required|numeric|min_length[9]|callback_uk_phone_check');
    $this->form_validation->set_rules('address', 'Address', 'trim|required|alpha_numeric_spaces');
    $this->form_validation->set_rules('post-code', 'Post Code', 'trim|required|alpha_numeric_spaces');


        $data = array(
            'what_licence' => $this->input->post('what_licence'),
            'initials' => $this->input->post('initials'),
            'lastname' => $this->input->post('lastname'),
            'email' => $this->input->post('email'),
            'tel_number' => $this->input->post('tel_number'),
            'address' => $this->input->post('address'),
            'post-code' => $this->input->post('post-code'),
        );

'what_licence' is for radio button which does not work If you could advise me it would be great. I am getting bald that doesn't work Thanks in advance

  • 写回答

1条回答 默认 最新

  • dpi96151 2016-08-09 08:37
    关注

    Where is: $this->form_validation->run() ?

    My code (is ok):

    $this->form_validation->set_rules('what_licence', 'What licence', 'required|in_list[1,2]');
            $this->form_validation->set_rules('initials', 'Initials', 'trim|required|alpha');
            $this->form_validation->set_rules('lastname', 'Last Name', 'trim|required|alpha|min_length[3]|max_length[30]');
            $this->form_validation->set_rules('email', 'Email ID', 'trim|required|valid_email|is_unique[yourself.email]');
            $this->form_validation->set_rules('tel_number', 'Phone Number', 'required|numeric|min_length[9]|callback_uk_phone_check');
            $this->form_validation->set_rules('address', 'Address', 'trim|required|alpha_numeric_spaces');
            $this->form_validation->set_rules('post-code', 'Post Code', 'trim|required|alpha_numeric_spaces');
    
            if ($this->form_validation->run()) {
                echo "SUCCESS FORM";
                $data = array(
                    'what_licence' => $this->input->post('what_licence'),
                    'initials'     => $this->input->post('initials'),
                    'lastname'     => $this->input->post('lastname'),
                    'email'        => $this->input->post('email'),
                    'tel_number'   => $this->input->post('tel_number'),
                    'address'      => $this->input->post('address'),
                    'post-code'    => $this->input->post('post-code'),
                );
                print_r($data);
            }else {
                echo validation_errors();
            }
    

    Pozdrawiam mistrzu :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 聚类分析 设计k-均值算法分类器,对一组二维模式向量进行分类。
  • ¥15 stm32c8t6工程,使用hal库
  • ¥100 有偿求易语言word文档取doc和docx页数方法或模块
  • ¥15 找能接spark如图片的,可议价
  • ¥15 关于#单片机#的问题,请各位专家解答!
  • ¥15 博通raid 的写入速度很高也很低
  • ¥15 目标计数模型训练过程中的问题
  • ¥100 Acess连接SQL 数据库后 不能用中文筛选
  • ¥15 用友U9Cloud的webapi
  • ¥20 电脑拓展屏桌面被莫名遮挡