Welcome Guest, Not a member yet? Register   Sign In
Validation and internal anchors
#1

[eluser]Joe_Archer[/eluser]
Hi, I have a view which contains multiple forms, each being processed by a different method in my controller. Basically what i'd like to know is: is there any way to add an internal anchor (#div-id) onto the URL when validation fails.

Currently when a validation error occurs, the user is redirected back to the form as expected, only the form in question, isn't at the top of the page, so the user has to scroll to the correct form to see what the individual errors were. I'd like to load the page directly at the div containing the form that the user submitted.

I can't think of any way to do it.

and yes I know having a big page of forms is poor interface design, but I have to do as my clients ask! Smile
#2

[eluser]Sumon[/eluser]
Code:
is it helpful for you
function add_item()
{
  if ($_POST)
  {
    if ($this->form_validation->run('portion_of_validation') == FALSE)
    {
        $data['msg'] = $this->form_validation->error_string();
        $data['default'] = $_POST;
                $this->load->view('view_page.php#div-id',$data);
    }
  }
  else
  {
       $this->load->view('view_page');
  }
}
#3

[eluser]Joe_Archer[/eluser]
This doesn't work for me.

If i do
Code:
$this->load->view('page_view.php#form1');

i get:

Unable to load the requested file: page_view.php#form1
#4

[eluser]Sumon[/eluser]
what about if you
use
Code:
redirect('add_item/#div-id);
instead of
Code:
$this->load->view('view_page.php#div-id',$data);
Hope this time it will work for you.
#5

[eluser]Joe_Archer[/eluser]
That doesn't work either, as I can then no longer use the
Code:
set_value('field_name')
function to maintain the form data.
#6

[eluser]Colin Williams[/eluser]
Just have your form actions contain the proper fragment identifier. And when the form goes well, you can redirect to a page w/o the fragment identifier.

Code:
<form action="<?= site_url('controller/function') ?>#div-id" method="post">
#7

[eluser]Joe_Archer[/eluser]
brilliant! I can't believe I didn't think of that.

thank you so much.
#8

[eluser]drewbee[/eluser]
Joe,

that was exactly what I was going to suggest. You just point the form to the anchor in the action attribute!

You can't do the previous because the load method is for loading the specified files, it really could care less about what exists where and how the page is layed out.




Theme © iAndrew 2016 - Forum software by © MyBB