duanjianxiu9400 2014-07-24 07:44
浏览 13
已采纳

无法从CodeIgniter控制器中的单选按钮收集数据

I am making a simple web form in codeigniter but facing a problem with radio button.

I have added two radio button. one is working perfectly, but the other one isn't

This is View:

            <div class="form-group">
                <label for="wai_banner_photography">Would you like to include photography in your website's banner?</label><br>
                <input type="radio" name="includephotography[]" value="yes"/>&nbsp;<label>Yes</label><br>
                <input type="radio" name="includephotography[]" value="no" />&nbsp;<label>No</label><br>
            </div>
            <div class="form-group">
                <label for="wai_provide_stockimage">Would you like us to provide you with suitable stock images?</label><br>
                <input type="radio" name="providestockimage[]" value="yes"/>&nbsp;<label>Yes</label><br>
                <input type="radio" name="providestockimage[]" value="no"/>&nbsp;<label>No</label><br>
            </div>

This is Controller part for collecting data:

    $include_photography = $this->input->post('includephotography');
    echo "26 ";
    print_r($include_photography);
    echo "<br/>";

    $pprovidestockimage = $this->input->post('providestockimage');
    echo "27 ";
    print_r($pprovidestockimage);
    echo "<br/>";

The output i am getting is:

enter image description here

I think, i am missing something small. Any help will be appreciable.

Thanks in advance.

Demo: http://forumtest.your365days.com/brief/

  • 写回答

2条回答 默认 最新

  • duanbu1998 2014-07-24 07:51
    关注

    Radio buttons used to return one value so their name must not be an array like this

    name="includephotography[]"
    

    it must be

    name="includephotography"
    

    and after this you must use

    echo $include_photography;
    

    instead of

    print_r($include_photography);
    

    may be this will help

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?