I have a little problem with codeigniter and form.
I'm, working on a project, where security is very important. I use codeigniter and bootstrap. I have main view, which includes navbar and some other html. In that main view i have <div id="change">
which i am changing via button group. With those buttons I am calling functions in controller which contains $this->load->view('pages/something', $data);
When i press on one of those buttons <div id="change">
is changed and in it, a view, is shown and link is not changed, so main view remains as it is. But when one of those buttons is pressed, view with form is shown. In it i use form_open('controller/function', $attributes);
. Problem is, that when i submit this form, link is changed and main view is not on screen anymore.
How can i achieve, that when i will submit form, all that will be changed is just <div id="change">
and not whole site.
I know i am bad in English, sorry. I appreciate any help. Thanks!
You want to refresh PART of the page and not the WHOLE page ? Maybe you need AJAX.
also, to make the link not changed, you have to change
config/routes.php
like this :
$routes['controller/method'] = "your link";
read this .
Hope it helps
You can submit the form with AJAX, here's a basic example with jQuery:
// this is the id of the form
$("#idForm").submit(function() {
var url = "path/to/your/script"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: $("#idForm").serialize(), // serializes the form's elements.
success: function(data) {
// 'data' is the response from the php script.
// Update <div id="change"> here.
}
});
return false; // avoid to execute the actual submit of the form. (This stops the URL changing).
});
Example modified from this answer .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.