dongzhanyan3667
2015-06-16 05:44 阅读 35
已采纳

如何在CodeIgniter验证后重定向到视图页面中的锚标签

This is my view page.here I put anchor tag for Event view

<a href="#tab_3" data-toggle="tab">Events</a>
<div class="tab-pane" id="tab_3">
    <h3 class="box-title">Events</h3>
    <form role="form" id="EventForm"  action="<?echo base_url()?>home/submit_event" method="post">
        <div>
            <label>Event Name</label>
            <input id="event_name" name="e_name" type="text" style="margin-right:20px;width:174px;height:21px;margin-left:46px ;"  class="form-control event_form">
            <?php echo form_error('e_name'); ?>
        </div>
</div>

controller

Here the insertion after validation.if the validation run is false I need to redirect the anchor tag.but I don't know how this possible.Here I am doing redirect to index that's my home page

function submit_event()
{
    $this->form_validation->set_error_delimiters('<div style="color:#B94A48">', '</div>');

    $this->form_validation->set_rules('e_name', 'Event Name', 'required');
    if ( $this -> form_validation -> run() === FALSE )
    {
        $this->index();
        //redirect(base_url().'');

    }
    else
    {
        $event_name=$this->input->post('e_name');
        $event_data=array(
            'event_name'=>$event_name,
        );
        $this->home_model->insert_event($event_data);
    }
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • 已采纳
    dongren1986 dongren1986 2016-06-07 13:07

    To redirect to an anchor in CI you should use redirect function like this :

    redirect('/controller/function#anchor', 'refresh');
    

    Hope that helps

    点赞 评论 复制链接分享
  • douyun1860 douyun1860 2015-06-16 06:32
    if ( $this -> form_validation -> run() === FALSE )
        {
            header('Location: http://www.example.com/');//your controller name
    
        }
    

    Header Function

    or

    if ( $this -> form_validation -> run() === FALSE )
        {
             redirect('/login/form/', 'refresh');//your controller name
    
        }
    

    Redirect

    点赞 评论 复制链接分享
  • duanpanhuo0618 duanpanhuo0618 2015-06-16 06:32

    codeigniter redirection can be achieved using the redirect method in the url helper. You can use this like this

    redirect('/your controller/method', 'refresh');

    Where 'your controller' is the controller that houses the method for the view page for new event add. And the 'method' is the method name inside the controller that loads the view. For reference go to this link codeigniter url helper

    点赞 评论 复制链接分享
  • droos02800 droos02800 2015-06-16 06:35

    This is how you can do it. First load the URL helper, then call the redirect() method

    $this->load->helper('url');
    redirect(base_url().'controller/method', 'refresh');
    

    Refer CodeIgniter Docs

    点赞 评论 复制链接分享

相关推荐