Php 在Joomla中提交后获取表单字段
我正在使用Flexi自定义代码创建一个按钮来向我发送电子邮件,但它似乎是随机工作的。我几乎从未得到Php 在Joomla中提交后获取表单字段,php,joomla,joomla3.0,Php,Joomla,Joomla3.0,我正在使用Flexi自定义代码创建一个按钮来向我发送电子邮件,但它似乎是随机工作的。我几乎从未得到$sendMail参数。但有时它是有效的,我收到电子邮件 <?php JHtml::_('behavior.formvalidator'); $jinput = JFactory::getApplication()->input; $sendMail = $jinput->get('sendMail', '', 'STRING'); if(isset($sendMail) &a
$sendMail
参数。但有时它是有效的,我收到电子邮件
<?php
JHtml::_('behavior.formvalidator');
$jinput = JFactory::getApplication()->input;
$sendMail = $jinput->get('sendMail', '', 'STRING');
if(isset($sendMail) && $sendMail == 'sendNow'){
$aId = JRequest::getVar('id');
$html = "";
$html .= "<h2>".$aId."</h2>";
$html .= "<p>test</p>";
$subject = "Request";
$from = array("noreply@test.com", "Website Contact");
$mailer = JFactory::getMailer();
$mailer->setSender($from);
$mailer->addRecipient("MY EMAIL");
$mailer->setSubject($subject);
$mailer->setBody($html);
$mailer->isHTML();
$mailer->send();
$submitted = "";
$submitted .= "Request confirmed";
echo $submitted;
}else{?>
<form action="<?php echo JUri::base() . basename($_SERVER['REQUEST_URI']); ?>" method="POST" name="adminForm" id="sendMailForm" class="form-validate">
<field type="hidden" value="sendNow" name="sendMail" class="required" />
<button type="submit" class="validate">SEND MAIL</button>
</form>
<?php }
?>
有很多奇怪的事情,但你可以先用“输入”替换“字段”。
不要使用JRequest,你已经有$jinput了
另一个问题可能是您有一个重定向,它将post请求更改为get请求。打开(chrome)调试器,检查网络标记(当您在那里时,检查sendMail输入是否确实在那里)我最后使用它禁用页面上的缓存
我可以从$\u服务器[“REQUEST\u URI”]
获取所有$\u get
参数,根据“field”应该可以正常工作。JRequest也不是实际问题的一部分。。。并将method=“POST”
与GET操作相结合也应根据您是否使用调试器检查了请求而工作?我是说你的post请求可以转换为get请求,这取决于操作url是什么。。。