On my website, I have a button which when clicked displays a feedback form in a popup window.
I need to pass the url in the PARENT window to a hidden field in the feedback form.
I tried:
<?php $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>
<input type="hidden" id="addressBar" name="addressBar" value= "<?php echo $url ?>"/>
The problem with the above code is that it passes the url of the current window, in my case, the url of the feedback popup window.
How do I pass the url of the parent window to that hidden field?
Many thanks for your help
You can try $_SERVER['HTTP_REFERER'] instead of REQUEST_URI (it gives you current uri)
but keep in mind that it's not reliable...
$url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'some_default_page.php';
Another way could be something like this ...
$cur_page_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo 'Feedback';
and then in popup.php just check if ref query string is set and retrieve its value.
Related
I have a PHP/HTML button who was link to
<? echo "Login"; ?>
Now I want change to other link to url www.button.com/index.html I changed the ine as :
<? echo "Login"; ?>
the second url is located on same server in other folder , but click on button not forward to link.
If you do not specify the protocol (e.g. http), the function assumes you want to go to a page on the same domain.
Try something like this:
<?="Login" ?>
Also, why are you using a JavaScript event? You could simplify this a lot by just putting the URL in the href attribute (href="//www.button.com").
i generate link with
<a onclick="window.history.pushState('', '', '?id=<?php echo $row['id']; ?>');"
and it generated URL like this
http://localhost/dpmerzon/order.php?id=MT01
"MT01" is example id for every link i pressed
So can i get "MT01" value with (PHP) $_GET['id'] without submitting the URL ?
you have to use AJAX if you want to submit somthing in background
explaine more what you gona do may can i help you
Been working on this since yesterday, having no success. I need to get the URL of a parent window into a form field on a child window so that I can send it along with customer from the form. Can anyone tell me how this can be done? I'd prefer it be done with PHP because I'm getting familiar with that.
Please and thanks.
If I did this on the parent page would it stor the parent's URL so that I could retreive it later?
<?php
$_SERVER['PHP_SELF'];
?>
and then to recall it on child perhaps:
if(!empty($_SERVER['PHP_SELF'])){
$link = $_SERVER['PHP_SELF'];
}else{
$link = "No URL submitted.";
}
is this about iframes?
If so, then:
parent.document.location.href - to get url of the document where the iframe is placed
top.document.location.href - get url of the document, whose url is in the address field of the browser
var childPopup = window.open();
var childForm = childPopup.document.createElement('form');
childForm.setAttribute('action', 'serverurl');
childForm.setAttribute('method', 'POST');
childPopup.document.body.appendChild(childForm);
var childText = childPopup.document.createElement('input');
childText.setAttribute('type', 'text');
childText.setAttribute('value', document.location.href);
childForm.appendChild(childText);
This is an example of Javascript that gets the URL of the parent window into a form field of the child window. Then this URL will be sent to the server as a parameter when the form is submitted.
have been working all day at this. apparently found at get parent.location.url - iframe - from child to parent
so you need <iframe src="http://your-site.com/framepage.php?parent=http://parentpage.com">
and in framepage.php (or whatever u has)
echo $_GET['parent'];
I have various links in my website that point to a specific form.
Whenever someone fills out the form, I want to be able to know what link led them to the form.
I want to do this without having to create an individual line of PHP code for every link I create in the. Instead, I want to have some PHP code that picks up something from that link, and maybe inserts it into a hidden text box that gets its value or text from something that I tag in the link.
For example:
User clicks a link.
That link directs them to a form.
The link carries an identification that activates PHP code
When I recieve the form, I know what link was clicked to get to that form.
I want it to work with links in emails I send out as well.
Based on the information in your post, it sounds like you just want to send a token/ id.
Goto Form
Now on the form you can grab the token:
$token = $_GET['token']; // use proper testing first
Then use a switch or if statements to run whichever code you need.
<input type="hidden" value="<?php echo $token; ?>">
Additional:
As the //use proper testing first comment indicates, you should make sure the token being passed is valid and sanitized in case of attack. One option is to have tokens stored in a database when generated and then compared when validating. Also look into htmlspecialchars() and even strip_tags() for sanitizing.
If the token fails to validate, you should not output and should even have a warning message/redirect that there was an error.
You can use HTTP Referer to achieve this. In PHP, you can use
$referer = $_SERVER['HTTP_REFERER']
Use this for example :
if (isset($_SERVER['HTTP_REFERER']))
{
$ref = $_SERVER['HTTP_REFERER'];
}
then in your form something like:
<input type="hidden" value="<?php echo htmlspecialchars($ref, ENT_QUOTES); ?>" name="ref" />
I am trying to pass a PHP GET variable to AJAX so the appropriate content according to the ID passed can be loaded on the same page but I don't know how to do it exactly. The ID is dynamically generated by a loop and the ID is given in the image hyperlinks below. So basically when they click on an image containing the link and the id that it is passed on, new content will load on the same page.
Below is the code.
<div id="myDiv">
<h2>Let AJAX change this text</h2>
You want to use the global $_GET variable.
Example:
www.some-url.com/script.php?id=1337
and in the script to access it:
echo $_GET['id']
> 1337
try to put parameter in the function you called...
onclick='loadXMLDoc(".$row['ID'].")'
or you can put the $row['ID'] in the input and set as hidden, then retrieve the value using ajax.
<input type="hidden" value="<?php echo $row['ID']; ?>" id="someid" />
retrieve
var ID = $('#someid').val();