首页 > 解决方案 > 提交表单后,需要在重定向到感谢页面之前在弹出窗口上显示变量值

问题描述

在将他/她重定向到感谢页面之前,我需要向用户显示一个弹出窗口。在弹出窗口中,我需要显示我生成的随机代码。弹出窗口包含一个“继续”按钮,单击它后,弹出窗口应关闭,然后重定向到感谢页面。

配置:

include("connectiondb.php");

# LIST EMAIL ADDRESS
$recipient = "forms@brand.com";

# SUBJECT (Subscribe/Remove)
$subject = "Hello ";

# RESULT PAGE
$location = "/thank-you.php";

## FORM VALUES ##

$sender = "support@brandname.com";

if (isset($_POST['Termscheck'])) {
    $termsCheck = "Yes";
} else {
   $termsCheck = "No";
}

# Generating unique alphanumaric code on each submission
function random_strings($length_of_string) 
{ 
    // String of all alphanumeric character 
    $str_result = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; 

    // Shufle the $str_result and returns substring 
    // of specified length 
    return substr(str_shuffle($str_result),  
                       0, $length_of_string); 
} 

$gcbcode = random_strings(6); 

# MAIL BODY
$subscriber_email = $_REQUEST['Email'];
$subscriber_subject = "THANK YOU";
$subscriber_email_data = file_get_contents('/email/queryFormThankyou.html');

# assigning values to email body   
$body .= "Name: ".$_REQUEST['Name']." \n";
$body .= "Email: ".$_REQUEST['Email']." \n";
$body .= "Number: ".$_REQUEST['Number']." \n";
$body .= "Company Name: ".$_REQUEST['Companyname']." \n";
$body .= "Industry: ".$_REQUEST['Industry']." \n";
$body .= "Design's Company Name: ".$_REQUEST['DesignCompanyName']." \n";
$body .= "Title of Your design: ".$_REQUEST['Titledesign']." \n";
$body .= "Caption: ".$_REQUEST['Caption']." \n";
$body .= "UniqueFeatures: ".$_REQUEST['UniqueFeatures']." \n";
$body .= "1st preferred medium of communication: ".$_REQUEST['Preferred_medium_one']." \n";
$body .= "2nd preferred medium of communication: ".$_REQUEST['Preferred_medium_two']." \n";
$body .= "Prefer Time to Call: ".$_REQUEST['Meeting_time']." \n";
$body .= "Agrees with Terms and policy: ".$termsCheck." \n";
$body .= "GCP code: ".$gcbppcode." \n";

if($_FILES["file"]["error"]>0)
{
    echo "FILE ERROR";
    die();
}

$info = pathinfo($_FILES['wordfile']['name']);
$ext = $info['extension']; // get the extension of the file
$newname = time().'.'.$ext; 

$target = '../Folder/'.$newname;
// move file to a folder
if (!move_uploaded_file($_FILES["wordfile"]["tmp_name"], $target)) { 
    //  echo "Sorry, there was an error uploading your file.";
    //  die();
    $target = 'No file attached';
 }

$body .= "file: ".$target." \n";

if (mysqli_connect_errno()){  echo "Failed to connect to MySQL: " . mysqli_connect_error(); }

else{ $sql = 'insert into abctable (name,email,phone,companyname,industry,DesignCompanyName,Titledesign,Caption,UniqueFeatures,Preferred_medium_one,Preferred_medium_two,meeting_time,agreeWithPolicy,gcp_code,uploaded_file_URL) values ("'.$_REQUEST['Name'].'","'.$_REQUEST['Email'].'","'.$_REQUEST['Number'].'","'.$_REQUEST['Companyname'].'","'.$_REQUEST['Industry'].'","'.$_REQUEST['DesignCompanyName'].'","'.$_REQUEST['Titledesign'].'","'.$_REQUEST['Caption'].'","'.$_REQUEST['UniqueFeatures'].'","'.$_REQUEST['Preferred_medium_one'].'","'.$_REQUEST['Preferred_medium_two'].'","'.$_REQUEST['Meeting_time'].'","'.$_REQUEST['Termscheck'].'","'.$gcbcode.'","'.$target.'")';

mysqli_query($con,$sql);
mysqli_close($con);
}


$headers = "From: " . $sender . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";


mail( $recipient, $subject, $body,   "From: $sender" ) or die ("Mail could not be sent.");
mail( $subscriber_email, $subscriber_subject, $subscriber_email_data, $headers) or die ("Unable to send email to subscriber");


header( "Location: $location" );

实际上,这项工作的目的是为用户提供一个唯一的代码,然后他将其用于进一步处理。

标签: phpformspopup

解决方案


这不是最漂亮的解决方案,但要在浏览器中弹出一个窗口,您可以使用 javascript。

$str_result = 'Hello World!';
echo '<script type="text/javascript">alert(\'' . $str_result . '\' );</script>';

您将前端行为与后端代码混合在一起,但这至少会向您的用户展示$str_result价值。


推荐阅读