This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi guys,
I'm implementing a simple contact form to send a mail.
Workflow:
- User fills in the form and submits
- OctoberCMS uses ajax framework to call the mail function
- Mail is sent (I received it in inbox)
- Ajax call is still running (no success response from Mail function)
Any ideas how to get it to give a success response?
My function:
function onContact()
{
$params = ['clientname' => post('name'), 'clientemail' => post('email'), 'clientmsg' => post('message')];
$sendmsg = Mail::send('xxx.contact', $params, function($message)
{
// Message recipient
$message->from('admin@xxxdomain.com', 'xxx Admin');
$message->to('xxx@gmail.com', 'xxx');
});
}
Last updated
OK I found a workaround... originally i wanted to use 'data-request-success' to trigger the success alert, but now forced to use 'data-request-update'. So following the example in the octoberCMS video:
function:
function onContact()
{
$params = ['clientname' => post('name'), 'clientemail' => post('email'), 'clientmsg' => post('message')];
$sendmsg = Mail::send('xxx.contact', $params, function($message)
{
// Message recipient
$message->from('admin@xxxdomain.com', 'xxx Admin');
$message->to('xxx@gmail.com', 'xxx');
});
$this['notice'] = 'success';
}
HTML:
<div id="contact-notice">
{% partial 'contact_notice' %}
</div>
<form role="form" id="contact-form"
data-request="onContact"
data-request-update="contact_notice: '#contact-notice'"
data-request-error="alert('Something screwed up, in the meantime pls call us.')"
class="contact-form" name="contact-form">
....
Partial:
{% if notice %}
<div class="alert alert-success">Thanks for your enquiry. We'll get back to you within the day.</div>
{% endif %}
Last updated
Hi, is this solution working for you? I've tryed to use it but i'm getting an error like contact_notice partial not found or something like this. My contact plugin structure is Plugins / Plugins author / Plugin name --> https://snag.gy/gWkZ7b.jpg
I have entered the PHP code in the contactForm.php file and in the components/contactform folder in the htm file where the form is i've entered the Html mentioned by you.
Where should I create the partial and how should I name it so the error with partial not found will not appear?
Thank you in advance.
Last updated
Hi,
I'm a little late I know but I just had the same problem.
I created the partial under the "partials" section in the "CMS" tab. That worked fine for me. This solution is quite ugly because the partial - where it is located right now - clearly belongs to the theme and not to the plugin as it should be and as it is the case with the rest of the plugin code. However, it functions as a workaround until I found a better solution. I'm still new to October CMS and have not looked into the AJAX framework.
I hope that helps those that are having that problem at the moment.
Last updated
1-4 of 4