使用php Form Processing Page有时会在输出中包含HTML元素

时间:2014-08-19 19:38:51

标签: jquery html forms

我正在使用Ajax将表单提交到表单处理页面。

它工作正常但随机发送给用户的输出包括用于构造传出消息的HTML元素的一部分或字母之间出现随机空格。

以下是处理的表格代码。

    // Data Time Stamp for submission
$submit_date = date("l jS F Y h:i:s A");

// Meeting Request Message Build code
$message = '<html><body>';
$message .= '<br>';
$message .= '<table class="emailform" rules="all" style="margin:10px auto; border:1px solid #f8981d; table-layout: fixed;">';
$message .= "<tr style='background: #f8981d; color:#FFFFFF' ><td colspan='2' class='centered-cell'><strong><center>Meeting Request Form</center></strong></td></tr>";
$message .= "<tr><td><strong>Name:</strong></td><td>" . $emp_Name . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . $emp_Email . "</td></tr>";
if($req_Name != "") {
    $message  .= "<tr><td><strong>Requestor's Name:</strong></td><td>" . $req_Name . "</td></tr>";
}
if($req_Email != "") {
    $message  .= "<tr><td><strong>Requestor's Email:</strong></td><td>" . $req_Email . "</td></tr>";
}
$message .= "<tr><td><strong>Function:</strong> </td><td>" . $meeting_Function . "</td></tr>";
$message .= "<tr><td><strong>Setup Date & Time:</strong> </td><td>" . $borrow_Date . " " . $time_Setup ."</td></tr>";
$message .= "<tr><td><strong>Start Date & Time:</strong> </td><td>" . $borrow_Date . " " . $time_Actual ."</td></tr>";
$message .= "<tr><td><strong>Return Date & Time:</strong> </td><td>" . $return_Date . " " . $end_Time ."</td></tr>";
$message .= "<tr><td><strong>Location:</strong> </td><td>" . $Loc ."</td></tr>";

if($contact_Number != "") {
    $message .= "<tr><td><strong>Contact Number:</strong></td><td>" . $contact_Number . "</td></tr>";   
}

if($hw_LcdProjectorQty != "") {
    $message  .= "<tr><td><strong>Projector</strong></td><td>Quantity: " . $hw_LcdProjectorQty . "</td></tr>";
}

if($hw_LaptopQty != "") {
    $message  .= "<tr><td><strong>Laptop</strong></td><td>Quantity: " . $hw_LaptopQty . "</td></tr>";
}

if($hw_WiredMouseQty != "") {
    $message  .= "<tr><td><strong>Wired Mouse</strong></td><td>Quantity: " . $hw_WiredMouseQty . "</td></tr>";
}

if($hw_WiredKeyboardQty != "") {
    $message  .= "<tr><td><strong>Wired Keyboard</strong></td><td>Quantity: " . $hw_WiredKeyboardQty . "</td></tr>";
}

if($hw_iPadQty != "") {
    $message  .= "<tr><td><strong>iPad</strong></td><td>Quantity: " . $hw_iPadQty . "</td></tr>";
}

if($hw_RemoteMouseQty != "") {
    $message  .= "<tr><td><strong>Remote Mouse</strong></td><td>Quantity: " . $hw_RemoteMouseQty . "</td></tr>";
}

if($hw_PowerStripQty != "") {
    $message  .= "<tr><td><strong>Power Strip</strong></td><td>Quantity: " . $hw_PowerStripQty . "</td></tr>";
}

if($hw_HandMicQty != "") {
    $message  .= "<tr><td><strong>Hand Microphone</strong></td><td>Quantity: " . $hw_HandMicQty . "</td></tr>";
}

if($hw_LapelMicQty != "") {
    $message  .= "<tr><td><strong>Lapel Microphone</strong></td><td>Quantity: " . $hw_LapelMicQty . "</td></tr>";
}

if($hw_MediaCart != "") {
    $message  .= "<tr><td><strong>Media Cart</strong></td><td>Quantity: " . $hw_MediaCart . "</td></tr>";
}

if($hw_PolyComPhone != "") {
    $message  .= "<tr><td><strong>Polycom Conference Phone</strong></td><td>Quantity: " . $hw_PolyComPhone . "</td></tr>";
}

if($Applications != "") {
    $message  .= "<tr><td><strong>Applications Requested:</strong></td><td>" . $Applications . "</td></tr>";
}

if($Comment != "") {
    $message  .= "<tr><td><strong>Comments/Special Instructions:</strong></td><td>" . $Comment . "</td></tr>";
}

$message .= "<tr style='background: #f8981d;  color:#FFFFFF'><td><strong>Status:</strong> </td><td>Request Submitted</td></tr>";
$message .= "</table>";
$message .= "</body></html>";

// send mails
$sentMail = @mail($to_Email, $subject, $message, $headers, $ical);

if(!$sentMail)
{
    $output = json_encode(array('type'=>'error', 'text' => 'Could not send mail! Please check your PHP mail configuration.'));
    die($output);
} else {
    $output = json_encode(array('type'=>'message', 'text' => 'Your Request has been sent. Thank you'));     
    die($output);
}
}

以下是此随机问题的示例。 (这是电子邮件表中的输出。请注意数量中有一个空格。

Borrow Request Form
Name:   My Name
Email:  myemail@email.com

Requestor's Name:   User Name
Requestor's Email:  user@email.com

Function:   Test Meeting Request
Setup Date & Time:  08/22/2014 
Start Date & Time:  08/22/2014 08:00am
Return Date & Time:  08/22/2014 09:00am
Location:   San Francisco
Laptop  Quanti ty: 1
Applications Requested: Citrix
Comments/Special Instructions:  Test Borrow Request without Submit to Service Desk Plus.
tatus:  Request Submitted

我确实看到其他随机字符的显示空间,Apostrophes,元素标签,如td随机显示在输出中。我有一种感觉,我可以缓冲它以防止这些输出工件,但我通过实例学习得最好。

谢谢,

1 个答案:

答案 0 :(得分:0)

在笔记本电脑之后没有:在代码中,所以不可能是一个。数量中间的空间非常神秘。

我不知道这是否正确,但如果在笔记本电脑之后:应该是,那么代码必须是这样的:

[...]<tr><td><strong>Laptop:</strong></td><td>Quantity[...]

以及我要说的另一件事,如果:是正确的,试试这个:

[...]<tr><td><strong>Projector Quantity:</strong></td><td>[...]

也许空间消失了;)