krasna Posted November 21, 2009 Share Posted November 21, 2009 I,m having hard time finding out how to pass the url name of a parent window to a popup. Can anyone please help? <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } //minimum characters allowed in the message box $msg_min_chars = "0"; //maximum characters allowed in the message box $msg_max_chars = "250"; $errors = array(); function validate_form_items() { global $msg_min_chars, $msg_max_chars; $msg_chars = "{".$msg_min_chars.",".$msg_max_chars."}"; $form_items = array( "name" => array( "regex" => "/^([a-zA-Z '-]+)$/", "error" => "Your name appears to be in improper format", ), "email" => array( "regex" => "/^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/", "error" => "email address is invalid", ), "message" => array( "regex" => "/.*/", "error" => "Your message is either too short or exceeds $msg_max_chars characters", ), ); global $errors; if(!preg_match($form_items["name"]["regex"], $_POST["your_name"])) $errors[] = $form_items["name"]["error"]; if(!preg_match($form_items["email"]["regex"], $_POST["your_email"])) $errors[] = "your ".$form_items["email"]["error"]; if(!preg_match($form_items["email"]["regex"], $_POST["friend_email1"])) $errors[] = "Friend 1 ".$form_items["email"]["error"]; if(strlen(trim($_POST["message"])) < $msg_min_chars || strlen(trim($_POST["message"])) > $msg_max_chars ) $errors[] = $form_items["message"]["error"]; if(trim($_POST["friend_email2"]) != "") { if(!preg_match($form_items["email"]["regex"], $_POST["friend_email2"])) $errors[] = "Friend 2 ".$form_items["email"]["error"]; } if(trim($_POST["friend_email3"]) != "") { if(!preg_match($form_items["email"]["regex"], $_POST["friend_email3"])) $errors[] = "Friend 3 ".$form_items["email"]["error"]; } return count($errors); } function email($from, $from_name, $to, $message) { //header("Location: thankyou.html");return; $headers .= "From: ".$from."\r\n"; $headers .= "Content-type: text/plain; charset=ISO-8859-1"; $u = curPageURL(); $your_domain_name = "www.mysite.com"; //edit what you want your vistors to see in their email here $subject = $from_name." sent you an invitation to $your_domain_name"; $your_message = "Hi!\r\n"; $your_message.= ucfirst($from_name); $your_message.= " wants you to check out:\r\n $u.\r\n"; $message=$your_message.stripslashes($message); if (mail($to,$subject,$message,$headers) ) { return true; } else { return false; } } function print_error($errors) { foreach($errors as $error) { $err.=$error."<br/>"; } echo "<div style=\"border:1px white solid; font-size:14px; font-weight:normal; color:#d6910a; margin:10px; padding:10px;\"> $err <div>"; } function form_process() { $from_name = $_POST["your_name"]; $from_email = $_POST["your_email"]; $to = $_POST["your_email"].",".$_POST["friend_email1"]; $message = $_POST["message"]; $error_count = validate_form_items(); if($error_count == 0) { if(email($from_email, $from_name, $to, $message)) header("Location: thankyou.html"); else { global $errors; $errors[] = "Email couldn't be send at this time. <br>Please report the webmaster of this error."; } } } if(isset($_POST["submit"])) form_process(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form id="mailform" method="post" action="<?php echo $PHP_SELF?>" > <table border="0"> <?php global $errors; if(count($errors) != 0){ print_error($errors); } ?> <tr> <td valign="middle" align="right">*Your Name:</td> <td><input type="text" name="your_name" id="name" size="40" value="<?php echo $_POST["your_name"]?>"></td> </tr> <tr> <td valign="middle" align="right">*Your Email:</td> <td><input type="text" name="your_email" id="email" size="40" value="<?php echo $_POST["your_email"]?>"></td> </tr> <tr> <td valign="middle" align="right">*Friend's Email:</td> <td><input type="text" name="friend_email1" id="name" size="40" value="<?php echo $_POST["friend_email1"]?>"></td> </tr> <tr> <td valign="middle" align="right">Friend's Email:</td> <td><input type="text" name="friend_email2" id="name" size="40" value="<?php echo $_POST["friend_email2"]?>"></td> </tr> <tr> <td valign="middle" align="right">Friend's Email:</td> <td><input type="text" name="friend_email3" id="name" size="40" value="<?php echo $_POST["friend_email3"]?>"></td> </tr> <tr> <td valign="top" align="right">Your comments:</td> <td><textarea name="message" id="message" rows=10 cols=31><?php echo $_POST["message"]?></textarea></td> </tr> <tr> <td colspan="2" align="right"> <i>(* required fields)</i> <input type="submit" value="submit" name="submit" > <!--#if expr="${isJS}" --> <input type="reset" value="clear form" onClick="clearform()"> <!--#endif --> </td> </tr> </table> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/182429-passing-url-name-from-parent-to-popup/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.