Search code examples
phpjoomlajoomla3.0

Get form fields after submit in Joomla


I'm using Flexi Custom Code to create a button to send an email to me, but it seems to be randomly working. I almost never get the $sendMail parameter. But sometimes it works, and I get the email...

<?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 } 
?>

I'm using Joomla 3.8.5


Solution

  • I ended up using CacheControl to disable cache on the page.

    And I can get all $_GET parameters from $_SERVER[“REQUEST_URI”]