Codeigniter PHP - loading view at anchor point

I have a form at the bottom of a long page, if the user fills out the form, but does not confirm that the page reloads in the usual encoder:

$this->load->view('template',$data);

however, because the form is down at the bottom of the page, I need a page to load there, like you, using HTML anchors. Does anyone know how to do this in an encoder?

I can not use codeigniter

redirect();

because it loses the object and the validation errors have disappeared. Other frameworks that I used as Yii, you can call the redirect function, for example:

$this->redirect();

which solves the problem because you are storing the object. I tried using:

$this->index()

inside the controller, which works fine as a redirect, but the validation errors are in another method from which the current page is loaded:

$this->item($labs)

but when i use this it gets stuck in a loop

Any ideas? I saw this question a lot on the net, but did not give clear answers. I am studying the use of codeigniter flash data, but I think this is a bit overkill.

greetings.

+6
source share
2 answers

I cannot vouch for it personally, but according to this thread , if you add an anchor to the action form, it will be work.

CodeIgniter Helper:

 <?php echo form_open('controller/function#anchor'); ?> 

Or vanilla HTML:

 <form method='post' action='controller/function#anchor'> 

If you were open to using Javascript, you can easily detect the $validation_failed variable and scroll accordingly. Or, even better, use AJAX.

Another option is to place the form at the top of the page?

+5
source

Well, as far as I understand your problem, it is not very related to the back end (codeigniter). You want the form at the bottom of the page to be "what-users-sees-on-page-load" (since you mention the bindings).

Now, what you can do, you can set the delimiters for validation error messages using:

 echo validation_errors('<div id="bottom_form_error">', '</div>'); 

Using jQuery ScrollTo , do:

 $( function() { $('#bottom_form_error').ScrollTo(); } ); 

And, the user will scroll to errors at the bottom of the page. Remember to enable jQuery as well.

The anchor fragment of the hash fragment is different - it scrolls in speed.

Hope this is what you wanted.


PS I ignore what is said below this line:

Does anyone know how to do this in an encoder?

as I felt this was not relevant to the question.

0
source

Source: https://habr.com/ru/post/925936/


All Articles