Welcome Guest, Not a member yet? Register   Sign In
Using anchors in form URLs
#1

[eluser]Kenneth Vogt[/eluser]
It is a pretty common approach for a controller to both process a form and render the form. In other words, you will often see a controller that looks like this:

Code:
class Account extends CI_Controller
{
  function index()
  {
    $this->form_validation->set_rules('email', 'Email Address', 'required|valid_email');
    if ($this->form_validation->run() == TRUE)
    {
      redirect('home', 'refresh');
    }
    else
    {
      $this->load->view('account');
    }
  }
}

My form might be far down the account.php page however. So it would make sense for me to use an anchor tag so that I can reference the url as:

Code:
./account.php#my_form
However I don't see any way to do this with load->view(). How can I accomplish this?
#2

[eluser]Kenneth Vogt[/eluser]
And the answer is you don't do it in the controller, you do it in the view. So instead of using:
Code:
form_open('account');
you would use:
Code:
form_open('account#my_form');
#3

[eluser]InsiteFX[/eluser]
To name an internal anchor:
place this just above your form.
Code:
<a name="top-form"></a>

To link to an internal anchor:
place this all over in your html code where you want the user to click to get to your form
Example code:
Code:
<a href="#top-form">Go to Form</a>

This will create an internal link in your html code.
#4

[eluser]Kenneth Vogt[/eluser]
While I can reference a page anchor with the form_open() method in the view script, that only allows for the use case where the page is being loaded after the posting of a form. If you need a more general case where you access it from the controller, you can use something like this:
Code:
redirect('account#settings', 'refresh');




Theme © iAndrew 2016 - Forum software by © MyBB