本文整理汇总了PHP中PBHelper::ajaxResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP PBHelper::ajaxResponse方法的具体用法?PHP PBHelper::ajaxResponse怎么用?PHP PBHelper::ajaxResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PBHelper
的用法示例。
在下文中一共展示了PBHelper::ajaxResponse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createResponse
function createResponse()
{
if (ob_get_contents()) {
ob_clean();
}
$response = array();
$response['error'] = 0;
$response['field'] = array();
$Validation = new PBValidation();
$Session = new PBSession();
$Session->create();
$id = $_POST['id'];
$formMetaData = $Session->getValue($this->getComponentId(), $id);
if ($formMetaData === false) {
exit;
}
$response['debug'] = $formMetaData['debug'];
$response['reset'] = $formMetaData['reset'];
if (!array_key_exists('field', $formMetaData)) {
exit;
}
if (!is_array($formMetaData['field'])) {
exit;
}
if (!count($formMetaData['field'])) {
exit;
}
$response['notice']['error'] = $formMetaData['notice']['error'];
$response['notice']['success'] = $formMetaData['notice']['success'];
$replace = array();
foreach ($formMetaData['field'] as $fieldIndex => $fieldData) {
if ($fieldData['type'] == 'submit') {
continue;
}
if (!array_key_exists($fieldIndex, $_POST)) {
$response['error'] = 1;
continue;
}
$value = $_POST[$fieldIndex];
if ($Validation->isNotEmpty($fieldData['name'])) {
if (!array_key_exists($fieldData['name'], $replace)) {
$replace[$fieldData['name']] = $value;
}
}
if ($fieldData['type'] == 'email') {
if ($Validation->isNotEmpty($value) || $fieldData['mandatory'] == 1) {
if (!$Validation->isEmailAddress($value)) {
$response['error'] = 1;
$response['field'][$fieldIndex]['notice'] = $fieldData['notice'];
}
}
} else {
if ($fieldData['mandatory'] == 1) {
if ($Validation->isEmpty($value)) {
$response['error'] = 1;
$response['field'][$fieldIndex]['notice'] = $fieldData['notice'];
}
}
}
}
if ($response['error'] == 1) {
PBHelper::ajaxResponse($response);
}
PBInclude::includeClass(PLUGIN_PAGE_BUILDER_LIBRARY_PATH . 'phpMailer/PHPMailerAutoload.php', array('PHPMailer'));
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
foreach ($replace as $index => $value) {
$formMetaData['sender']['name'] = preg_replace('/\\(' . $index . '\\)/', $value, $formMetaData['sender']['name']);
$formMetaData['sender']['email'] = preg_replace('/\\(' . $index . '\\)/', $value, $formMetaData['sender']['email']);
}
if ($Validation->isEmailAddress($formMetaData['sender']['email']) && $Validation->isNotEmpty($formMetaData['sender']['name'])) {
$mail->SetFrom($formMetaData['sender']['email'], $formMetaData['sender']['name']);
$mail->AddReplyTo($formMetaData['sender']['email'], $formMetaData['sender']['name']);
}
$mail->AddAddress($formMetaData['recipient']['email'], $formMetaData['recipient']['name']);
$recipientAdditionalData = mb_split(';', $formMetaData['recipient']['additional']);
foreach ($recipientAdditionalData as $value) {
$recipientAdditional = mb_split(':', $value);
PBHelper::removeUIndex($recipientAdditional, 0, 1);
if ($Validation->isEmailAddress($recipientAdditional[1]) && $Validation->isNotEmpty($recipientAdditional[0])) {
$mail->AddAddress($recipientAdditional[1], $recipientAdditional[0]);
}
}
if ($formMetaData['debug'] == 1) {
$mail->SMTPDebug = true;
}
if ($Validation->isNotEmpty($formMetaData['sender']['smtp_host'])) {
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Port = $formMetaData['sender']['smtp_port'];
$mail->Host = $formMetaData['sender']['smtp_host'];
$mail->Username = $formMetaData['sender']['smtp_username'];
$mail->Password = $formMetaData['sender']['smtp_password'];
$mail->SMTPSecure = $formMetaData['sender']['smtp_secure_connection_type'];
}
$mail->Subject = $formMetaData['message_subject'];
$value = array_map('htmlspecialchars', $replace);
$body = $formMetaData['message_content'];
foreach ($replace as $index => $value) {
$body = preg_replace('/\\[' . $index . '\\]/', $value, $body);
//.........这里部分代码省略.........