This question already has answers here:
Stop execution after call $this->load->view()
(6 answers)
PHP/codeigniter - use of exit()
(8 answers)
Forcing CodeIgniter to send view and stop working
(3 answers)
Closed 2 years ago.
I have a page at admin/show_queries with a form in codeigniter like so
<form action="" method = "post">
<input....
<input....
<input type = "submit" name = "view_query" />
</form>
Then in my controller Admin.php, I try to catch the event when someone presses view_query
public function show_queries(){
...
...
if($this->input=>post('view_query'){
$this->view_query_function();
}
$this->load->view('elex/show_queries');
}
In the same file Admin.php my view_query_function:
public function view_query_function(){
//DO Something
...
...
$this->load->view('elex/view_queries');
}
All of this is working and I'm able to go to the View_queries page without trouble.
Here's the problem, that I'm facing<
When I click the button view_queries and the view_queries page loads, it loads on top of show_queries page. Means, when the view_queries page is loaded, I can scroll down and I see the show_queries page, which should not be there. I check the url, and the url hasn't changed either.
What am I doing wrong here?
Add a return after calling the function:
if($this->input->post('view_query'){
$this->view_query_function();
return;
}
Related
This question already has answers here:
Accessing session from TWIG template
(5 answers)
Closed 9 months ago.
I want to add my javascript popup code which is in an html file to my php function.
It's a visitor counter in php. I want when visitors visit the page 4 times my popup html js is displayed
Do you just mean like this?
if ($increment == true) {
$compteur_actuel = $session->get('compteurClicsFreemium', 0);
$session->set('compteurClicsFreemium', $compteur_actuel+1);
if ($compteur_actuel > 4) {
?>
<div>
Your HTML code here
</div>
<?php
}
}
This question already has answers here:
PHP Redirect to new page after form submission
(5 answers)
Closed 6 years ago.
I have a contact contact form that after submitting a message, if it is sucess it should go to the success.php page, but im having a issue, i want this page only be available when the user is redirect from the sendForm.php. How should i make this permission in my script?
Many ways simplest way is to send parameter in URL ex. success.php?ok=1
<form action="success.php?ok=1" ...>
And at top of success.php page write:
<?php if( isset($_GET['ok']) ){
?>
html page code here
<?php }else{
//code if not redirect from sendForm.php
?>
or send POST request to look more professional without annoying url parameters and use isset($_POST['ok']).
This question already has answers here:
How to call a PHP function on the click of a button
(13 answers)
Closed 7 years ago.
I have a problem with calling a phpfunction from a onclick() event.
<button onclick=delete($a) >click here</button>
<?php
Function delete($a)
{
----statements----
}
?>
Please help me solving this functiom call
You cannot call a php function from a javascript onclick event that way. php is strictly server side, the only way is to make an ajax call to a script that will run the function and return the result. Once the page is served, all trace of php disappears, there is no reference or anything of php left in the client side.
This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 8 years ago.
i dont know what to say but, i have a banner with a session variable, if that session variable is set and have a value 1 then i have displayed that banner. i also have a button to hide that banner and i have called a javascript function onclick that button.
so i have created a simple javascript function and added some php code with php tag to unset the session variable. I can also use ajax to unset the session variable. but i was thinking to do that with that function why to do ajax call.
i have some code:
<?php if($_SESSION['SHOW_BANNER']==1){ ?>
<div id="banner">Banner goes here</div>
<button onclick="hideit()">Hide</button>
<?php } ?>
Here is jquery function:
<script>
function hideit()
{
<?php unset($_SESSION['SHOW_BANNER']); ?>
$("#banner").hide();
}
</script>
Each time when i reload the page, the session variable is unset.
Any Help..
You can't execute PHP code directly from JavaScript. PHP code is executed when page is rendering on server side, and if you have syntax like:
function hideit()
{
<?php unset($_SESSION['SHOW_BANNER']); ?>
$("#banner").hide();
}
It executes every time unset when page is loaded and result of this code is returned to JavaScript. Only way to unset session variable is to execute code on server side, you can do this with simply ajax call.
function hideit()
{
$("#banner").hide();
$.get("hideBanner.php");
}
And in hideBanner.php just execute
<?php unset($_SESSION['SHOW_BANNER']); ?>
This question already has answers here:
Redirecting after form submission with user input in the URL
(3 answers)
Closed 8 years ago.
I have a form that filters the products by some characters such as size/price etc..
I would like to change the url variables values according to the filter result for example:
Before submit:
www.exmaple.com/product.php
after submit
www.example.com/product.php?size=1&price=300
How can I do that?
Try something like this
if(isset($submit))
{
//After clicking the button , do some operations here....
//Your code...
//More code...
header("location:product.php?size=1&price=300");
}
EDIT :
This is most common error check this thread. Also, if that doesn't work. Replace your header with
echo "<script>document.location.href=product.php?size=1&price=300</script>";