Php Joomla3-表单提交后如何显示成功通知(后期处理)

Php Joomla3-表单提交后如何显示成功通知(后期处理),php,forms,joomla3.0,Php,Forms,Joomla3.0,我正在编写一个自定义联系人表单,此表单是一个标准的POST表单。 该表单如下所示: <form action="/path/to/my/phpfile.php" method="post" id="form"> <input type="email" id="email" name="email"/> <input type="text" id="name" name="name"/> <inp

我正在编写一个自定义联系人表单,此表单是一个标准的POST表单。 该表单如下所示:

<form action="/path/to/my/phpfile.php" method="post" id="form">
          <input type="email" id="email" name="email"/>
          <input type="text" id="name" name="name"/>
          <input type="submit" value="submit"/>
</form>
<?php
$email_from = $_POST['email']; 
$fromname = $_POST['name'];
$email_to = 'test@email.com';

$email_subject = 'Subject text....';
$email_message = 'Email message.....';

//Send the email
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 

header('location: http://www.mywebsite.com/destination/');
?>
if($_GET["message"] == "success") {
            $displaymsg = "My message text..";
            JFactory::getApplication()->enqueueMessage($displaymsg);
}

现在,我的PHP文件如下所示:

<form action="/path/to/my/phpfile.php" method="post" id="form">
          <input type="email" id="email" name="email"/>
          <input type="text" id="name" name="name"/>
          <input type="submit" value="submit"/>
</form>
<?php
$email_from = $_POST['email']; 
$fromname = $_POST['name'];
$email_to = 'test@email.com';

$email_subject = 'Subject text....';
$email_message = 'Email message.....';

//Send the email
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 

header('location: http://www.mywebsite.com/destination/');
?>
if($_GET["message"] == "success") {
            $displaymsg = "My message text..";
            JFactory::getApplication()->enqueueMessage($displaymsg);
}

因此,我想做的是将成功通知/消息显示为标准Joomla系统消息

我注意到Joomla消息前端包含在我的模板中的这个容器中:

<div id="system-message-container">
<div id="system-message">
<div class="alert alert-notice"><a class="close" data-dismiss="alert">×</a>
<h4 class="alert-heading">Header text...</h4>
<div>
        <p>Message....</p>
</div>
</div>
</div>
</div>

×
标题文本。。。
消息

问题是,如何在PHP文件中创建代码,将系统消息传输到Joomla中的目标页面?
我用的是Joomla v。3.2.1默认情况下,当用户在提交表单joomla后单击提交底部时,转到“/path/to/my/phpfile.php”方向。当您向这个方向回显一些文本时,这些文本将显示给用户。

您可以使用第三方扩展,将php代码显示为文章中的模块。这样你就可以编写自己的成功通知

以下是为您执行此任务的扩展列表:


我会尝试不使用Jumi,它可以工作,但在我的例子中,它产生了很多错误。

我终于找到了如何接入内置Joomla通知消息系统的方法。结果很简单

要显示系统消息,只需使用以下行之一:

//Standard message
JFactory::getApplication()->enqueueMessage($mymessage);

//Notice message
JError::raiseNotice(100, $mymessage);

//Warning message
JError::raiseWarning( 100, $mymessage );
所以在我的例子中,我所做的是发送一个URL变量,例如?message=success 在我的模板文件中,我简单地做了一个if语句,如下所示:

<form action="/path/to/my/phpfile.php" method="post" id="form">
          <input type="email" id="email" name="email"/>
          <input type="text" id="name" name="name"/>
          <input type="submit" value="submit"/>
</form>
<?php
$email_from = $_POST['email']; 
$fromname = $_POST['name'];
$email_to = 'test@email.com';

$email_subject = 'Subject text....';
$email_message = 'Email message.....';

//Send the email
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 

header('location: http://www.mywebsite.com/destination/');
?>
if($_GET["message"] == "success") {
            $displaymsg = "My message text..";
            JFactory::getApplication()->enqueueMessage($displaymsg);
}

我希望这能帮助其他与我处境相同的人。

此外,如果您将用户发送到的位置仍然在您的Joomla内!网站,你可以显示一个Joomla!系统消息,并且仍然可以使用Joomla的内置重定向功能进行重定向,即当用户到达目标页面时显示消息。像这样:

  // give joomla the message to display...
  $app = JFactory::getApplication();
  $app->enqueueMessage('A message for the user');

  // ...and still do a redirect
  $app->redirect('http://www.myJoomlaSite.com/index.php?option=com_whatever');

因此,即使在执行重定向之后,只要页面在您的Joomla内,您的用户仍然会在目标页面上获取您的消息!site

Hi,你能详细说明一下你的意思吗?当你想在joomla中提交表单时,将action设置为form非常重要。如果你想根据mvc创建一个组件,你必须将action设置为“index.php?option=com\u componentname&view=viewname”。你使用的是mvc模型吗?否,这是一个完全定制的PHP文件,仅用于处理此特定的联系人表单。我在想/希望可以通过URL参数传输系统消息,可能是因为“获取数据”,您不能在joomla上使用。如果您想在joomla上使用它,您必须创建一个模块或组件或将其包含在模板文件中。好的,您能告诉我如何在模板文件中生成系统消息吗?我想我可以在特定条件下在模板文件中生成自己的系统消息,然后在URL中传递特定GET数据时生成触发消息。是的,我已经在为自定义HTML、CSS、jQuery和PHP“Flexi自定义代码”使用这样的插件/模块但是我想要的是使用内置的Joomla消息系统,并根据来自外部post脚本的响应来回显消息。我特别想要的是能够通过使用URL参数或类似的东西触发这个Joomla消息系统。