2015-06-16 28 views
2

这是我的看法page.here我把锚标记为插入后如何重定向笨验证后,锚定在视图页面标签

<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> 

控制器

这里事件 图validation.if验证运行是false我需要重定向锚标记。但我不知道这是如何可能的。在这里我做重定向索引这是我的主页

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); 
    } 
} 
+0

你需要做什么?清除位 –

+0

还是我在事件section..if验证做验证是假的我可以存在于同一事件部分 – robins

+0

所以使用'header' funtion –

回答

1

要重定向到一个锚在CI你应该使用重定向功能是这样的:

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

希望帮助

0
if ($this -> form_validation -> run() === FALSE) 
    { 
     header('Location: http://www.example.com/');//your controller name 

    } 

Header Function

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

    } 

Redirect

0

笨重定向可以使用在url辅助重定向方法来实现。你可以像这样使用

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

其中'您的控制器'是控制器,其中包含新事件添加视图页的方法。 'method'是加载视图的控制器内的方法名称。作为参考去这个链接 codeigniter url helper

0

这是你如何能做到这一点。首先加载URL helper,然后调用redirect()方法

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

参考CodeIgniter Docs