after click the submit button on my form, how do I add the anchor "#work" in the url without reloading the page?
example: www.test.it/#work
i use header('Location: #work'); but refresh my page.
Update:
I use "jessica" solution:
I think the page is reloaded
But don't work, ca see here: http://www.substellar.it/ftende/contatti/
I think the page is reloaded
Just add #work to the action in form for it to show up in the link.
<form action = "url#work">
Related
I am new to php. I have Form on a page with a button that once clicked it pops up another sub page :
onclick="newPopup('page2.php','750','500')
page2.php has another button, I want to be able to redirect the Main Page to another url using this pop-up.
How can I do this?
If you want to redirect the main page on a button click in the popup, you need to do this with JS, not PHP.
Add this to the button in the popup:
onclick="window.opener.location.href='someurl.php'";
From a popup, you can access the page/window that opened the popup with: window.opener. This means that you also can call functions on the main page: window.opener.someFunctionOnTheMainPage().
On click of button, you can execute below JavaScript:
window.opener.location.href = 'new URL';
This will redirect your parent page to the new URL.
I am making an e-commerce website where I have lots of products. If a user goes to any product items page and submits any form there then they should come on the same page.
So, how to come on the same page?
On the formular target page set:
header('Location: http://www.example.com/same_page');
Leave action attribute of form blank. Like so:
<form action="" method="post">
Or
<form action="#" method="post">
On your opening form tag add
action="submit.php"
then once it goes to that page when the submit button is hit add this
to the bottom of that php page:
header("Location: success.html OR success.php");
If you want to submit various forms on same page and then go back to the page where the form is submitted, you must also send the form URL of the page where it was sent, preferably in a hidden element. And after processing form redirect to URL stored in hidden.
You can use this :
header('Location: filename.php);
If you get any $_POST errors put it in a condition: if(isset[$_POST])
Thank You All. I Got My Answer
$_SERVER['REQUEST_URI']; will give the current URL with query strings.
Like my page is 'products.php?Product=20'
echo $_SERVER['REQUEST_URI']; =>/products.php?Product=20
So, we can directly use this in header location.
I'm using Fancybox 2 to display some forms on my website. The form comes through from an external page into an IFrame to let the user post a message, kind of like twitter does. However I want the user to be re-directed after the form has been posted. So they post the form to a database, the Fancybox window shuts down and then they are redirected to the posts page where they see their newly posted message. Is there a way of doing this succesfully?
You can try this:
<script>
if(data == 1){
//window.location.replace("dashboard.php"); //will open the page in the fancybox
parent.$.fancybox.close(); //will close the fancybox
//parent.window.location.replace( your_url_here ); //your redirecting URL here
parent.window.location.href = 'dashboard.php'; //your redirecting URL here
}
</script>
I would recommend you to use a real form rather than a post action. You are not really using form submission otherwise, but just a POST request.
If you do that, you could use the target="_top" inside the <form tag and submit the results using the submit function of jQuery.
i have simple coding problem. i have created a page with textbox and share button. the page also contains one Points up button.
i had a problem with that points up button that when the user click on that button and refresh the page ... a window ask for resend of information
for that i have used following code which works fine.
`header('Location: samepageurl.php');
exit;`
but the problem with above code is when user scroll down page and click the button. the page automatically scrolls up. and user have to manually scroll it down.
what i want is the page should refresh but it should be on the same location where it was.
if the problem is still unclear please refer the following images
You can set a fragment identifier.
eg:
<a name="points_up"></a> <!-- this needs to be near that button, the page will scroll exactly where the element is -->
and redirect him to:
header('Location: samepageurl.php#points_up');
die;
Mihai answer is correct, but as you said that fragment identifier is not working because each user has points up button, you can pass user id as a fragment identifier and make a hidden(display : none;) <a> tag and pass the user id in front of each user...
Like this:
You can set a prefix before a user id too (optional)
<a name="pu12345" style="display: none;"></a>
<?php
header('Location: whatever.php#pu12345');
exit;
?>
You can send the request via ajax instead relying on the normal form submission. That will not affect the scrolling of the current page.
Add this line at the bottom of your page before the the <\body> tag
<button id="PageRefresh">Refresh a Page in jQuery</button>
<script type="text/javascript">
$('#PageRefresh').click(function() {
location.reload();
});
</script>
I want to execute a Action and stay on the same page.
I created the link to eh action like this:
<?php echo(link_to('Add to Watchlist', 'housing/addToWatchlist')) ?>
which executes this action with a redirect
echo('ADDING TO THA WATCHLIST');
$referrer = $request->getReferer();
return $this->redirect($referrer);
as suggested here: symfony link to change language and stay on the page
This solution works but unnecessary reloads the page, which may be necessary to change the language but not to add an item to a Watchlist.
Without reloading the page you need to use Javascript and an Ajax approach.
http://www.symfony-project.org/jobeet/1_4/Propel/en/18
Also check out link_to_remote.