Change the url after clicking the submit button [duplicate] - php

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>";

Related

How to add my html javascript popup to my php function? [duplicate]

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
}
}

Codeigniter loads views from functions on top of another [duplicate]

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;
}

Redirect header php to success page [duplicate]

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']).

Is it possible to apply jquery to content rendered by external php (ajax)? [duplicate]

This question already has answers here:
Events triggered by dynamically generated element are not captured by event handler
(5 answers)
Closed 8 years ago.
page-one.php contains such jquery
$.post("___for_ajax_process.php", data_to_send_ajax_post, function(data_edit_content) {
$('#show_result').html(data_edit_content);
});
in #show_result i see content from ___for_ajax_process.php
Rendered content contains many checkboxes and want to create check all. check all is named draft_check_all.
At first want to check what happens if I click the checkbox.
$("#draft_check_all").click(function(){
alert ( 'click test' );
});
And I do not see alert ( 'click test' ); No popup at all.
Then View source and I do not see source code for content rendered by ___for_ajax_process.php
As understand in such way can not apply jquery to content from ___for_ajax_process.php? What if place $("#draft_check_all").click(function(){ in ___for_ajax_process.php? Are there any solutions for such situation?
Solution
placed jquery in external php and all works!
A better solution would be event delegation.
$('#show_result').on('click', '#draft_check_all', function () {
...
});

Is it possible to increase the number of rows of a textarea using Javascript event? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to change the number of rows in the textarea using jQuery
I'm trying to build a comment box that simulates Facebook, where Shift+Enter increases the rows in the textarea while Enter submits the form. I already can capture both events correctly, I'm just wondering if Javascript alone can edit a page's element attributes since it has already been loaded, or if there's another way to do it.
EDIT:
My code block looks like this:
$(this).keypress(function(e) {
if (e.which == 13 && e.shiftKey) {
this.rows++;
e.preventDefault();
};
});
But this still doesn't seem to work. Again, I've tried placing alerts into this code block so I'm certain the Shift+Enter event is captured, but the textarea's rows just doesn't increase. Any ideas why? :/
$("textarea").keydown(function(e) {
if(e.shiftKey&&e.keyCode==13) {
this.rows++;
}
})

Categories