Jump to content

Grabbing a URL via Popup


rohan.weston

Recommended Posts

Hi guys. I'm very new to PHP, and I'm trying to create a simple mail script.

 

Mail a friend

A user will click an image on the site which will open a pop up box. They input their name and the email of the friend that they want to send the current URL to. The email will send the current URL via email and display a confirmation message once it has sent successfully.

The friend will receive an email with a link to the URL.

 

The problem

The email part works fine, it's the URL in the message that is the issue. When the user clicks the 'Email a friend' it opens a popup box - which is where the URL is being grabbed from and emailed.

Is there a way to grab the URL from the page before the popup?

 

Here is my (rather amateur) code. Also, feel free to let me know if I can make improvements to it if anything seems a bit strange!

 

The popup link:

<a onclick="window.open(this.href,'win2','width=400,height=350,menubar=yes,resizable=yes'); return false;" title="E-mail" href="mailform/form.html">Send to a friend</a>

 

The popup form:

 

<html>

<body>

<form method="post" action="code.php">

    Friends Email: <input name="email" type="text" /><br />

    Your Name: <input name="name" type="text" /><br />

    <input type="submit" />

</form>

</body>

</html>

 

 

The PHP code:

 

<?php

// Declaring Variables

    $email = $_REQUEST['email'] ;

    $name = $_REQUEST['name'];

    $geturl = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

    $message = "Hello. $name has suggested a page for you to view on our website. Please click the following link: $geturl";

 

// Email Settings

    mail( $email, "Send page to a friend",

        $message, "From: Timaru District Council" );

    header( "Location: http://www.c4clever.com/sandbox/mailform/sent.html" ); // Confirmation page (Change this to appropriate URL)

?>

 

Feel free to test it out if you want to (http://www.c4clever.com/sandbox)

 

 

Looking forward to replies, thanks in advance!

Link to comment
Share on other sites

If you know the url, you could embed it on the link the users have to click, then grab that value  on the popup through $_GET['url'];

 

Like so

 

<a href="example.com/popup?url=example.com" target="_blank">Share with Friend</a>

 

and on your popup page, just grab the contents of the $_GET['url'];

 

Let me know that helps.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.