简体   繁体   English

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

[英]how to redirect to anchor tag in view page after CodeIgniter validation

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

To redirect to an anchor in CI you should use redirect function like this :要重定向到 CI 中的锚点,您应该使用如下重定向功能:

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

Hope that helps希望有帮助

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 重定向

codeigniter redirection can be achieved using the redirect method in the url helper. codeigniter 重定向可以使用url helper 中的redirect 方法来实现。 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有关参考,请转到此链接codeigniter url helper

This is how you can do it.这就是你可以做到的。 First load the URL helper , then call the redirect() method首先加载URL helper ,然后调用redirect()方法

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

Refer CodeIgniter Docs参考CodeIgniter 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM