Goto partials > contact.htm
in form add data-request="onSend" data-request-success="alert('We have recieved your email.. we\'ll get back to you shortly')"
data-request-error=“alert(jqXHR.responseText);” instead of method="post" action="#"
Now goto layout -> default.htm and switch from markup to the code tab and paste this
function onSend()
{
// Collect input
$name = post('name');
$email = post('email');
$subject = post('subject');
$msg = post('msg');
// Form Validation
$validator = Validator::make(
[
'name' => $name,
'email' => $email,
'subject' => $subject,
'msg' => $msg,
],
[
'name' => 'required',
'email' => 'required|email',
'subject' => 'required',
'msg' => 'required',
]
);
if ($validator->fails())
{
$messages = $validator->messages();
throw new ApplicationException($messages->first());
}
// All is well -- Submit form
$to = System\Models\MailSettings::get('sender_email');
$params = compact('name','email','subject','msg');
Mail::sendTo($to, 'yourappname.website::mail.contactform', $params);
return true;
}
Now goto Settings page from the nav menu and in Mail choose mail template. Create a new template with code as yourappname.website::mail.contactform
Fill the subject field as Message from YourAppName In the body fill
Name: {{name}}
Email: {{email}}
Subject: {{subject}}
Message: {{msg}}
It should look like this..
Press create and close, and open the template you just created and send a test email. If the mail fails to send and gives a flash error you'll need to goto Mail Settings in the same section and fix the settings (I use Mailgun). Now if the mail test works, go try the live form in the website with random data. It should work fine!
Minor Update: I changed message
into msg
as the mail template gave an error on using the word message
. Assume this is a reserved word and do not use it in mail templates.
Last updated
Thanks a lot =) mail works for me fine!
I just replaced data-request="onSend"
instead data-request="onSend()"
and All 'messages' instead 'message'.
Thank you very much.
Last updated
Moshin thanks for your post. Can you please extend the code and explain how I can build a form with checking for values from a dropdown field, where I become different values. Do I put a simple If-Statement in the beginning, such like
if ($name == value1)
{
$to = mail@test.test
}
so that on a each dropdown field a different recipient adress is set. How do I manage this?
Last updated
Thanks for the help with this.
When I send a test message, it errors out.
If I do not add any text to the HTML Mail template, the email sends - but of course then the data is not being sent in the email.
Error : http://maggiesbooks.ca/october-error.txt
Last updated
Hi. I used this exact same method. It worked but the message seems to be sent twice. Any advice on this? thanks. here is the link http://goo.gl/KoJBhb
Last updated
evanomondi79231 said:
Hi. I used this exact same method. It worked but the message seems to be sent twice. Any advice on this? thanks. here is the link http://goo.gl/KoJBhb
Your website has some issues. October JS files are not loaded correctly. Add these lines to your website
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="{{'assets/js/jquery.js'|theme}}"><\/script>')</script>
Just after </footer>
in the layout. And also download and keep jquery.js inside assets/js folder. Now re-check whether you still face this issue.
Mohsin said:
evanomondi79231 said:
Hi. I used this exact same method. It worked but the message seems to be sent twice. Any advice on this? thanks. here is the link http://goo.gl/KoJBhb
Your website has some issues. October JS files are not loaded correctly. Add these lines to your website
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script>window.jQuery || document.write('<script src="{{'assets/js/jquery.js'|theme}}"><\/script>')</script>
Just after
</footer>
in the layout. And also download and keep jquery.js inside assets/js folder. Now re-check whether you still face this issue.
Hi Mohsin thanks for your help, I did exactly the above but is still sends one email twice. Any other sussgestions? Thanks in advance
No. It’s still not fixed. You’ll have to fix this issue by making sure the JQuery library loads before framework.js gets called.
The problem is that you are loading framework.js in the <head>
section. You have to remove that.
Also I noticed in your code:
<script src="/modules/system/assets/js/framework.js"></script>
<script src="/modules/system/assets/js/framework.js"></script>
So you called it once in the head section (which should be removed) and twice before the closing body tag--Calling it one time is enough! Just search through your pages and layout for {% framework %} and make sure it’s not present in any page code. Just in your layout and only ONCE at the end before the closing body tag.
Last updated
Rsl sandoval said:
I'm try this Now goto layout -> default.htm and switch from markup to the code tab and paste this....
But i dont understand very good Can your explain me again?????
If you have teamviewer or skype I can take a look and help you fix it.
thanks for the prompt response and I could configure either sending message from the form I now seeking information on how to clear the form fields once sent the message
Rsl sandoval said:
thanks for the prompt response and I could configure either sending message from the form I now seeking information on how to clear the form fields once sent the message
Easy peazy.
data-request-success="alert('We have recieved your email.. we\'ll get back to you shortly’); this.reset();"
See the this.reset();
. That’s all you need.
.... thank you very much for the help, now I have another problem when I try to edit a file I get blank and I returned to reinstall and install the theme "multi" and still have the same problem , that is in the online hosting in localhost works well , any suggestions?
Could anybody help me with contact form on [HSE KZ]: http://hse.kz/contacts.
I don't understand what i have to do for create this form handler.
As mentioned by Mohsin, I have done:
- Adding data-request string to <form ...>
- Creating partial, where form is included
- Add to layout-> default.htm -> code But it doesn't work, it shows the error messages such as "Couldn't found onSend..." or error " ...not found ... System\Models\MailSettings::get('sender_email');"
Could somebody advice me?
Hi. You have done it wrong. You need to use onSend
and not ::onSend
. Also, you have not added this function to the layout instead of the page. That’s why you a handler not found error. So, goto CMS tab -> Pages -> Your Contact Page and then click on the Code section and paste in the onSend function as I had given in the first post.
conprefor16116 said:
Could anybody help me with contact form on [HSE KZ]: http://hse.kz/contacts.
I don't understand what i have to do for create this form handler.
As mentioned by Mohsin, I have done:
- Adding data-request string to <form ...>
- Creating partial, where form is included
- Add to layout-> default.htm -> code But it doesn't work, it shows the error messages such as "Couldn't found onSend..." or error " ...not found ... System\Models\MailSettings::get('sender_email');"
Could somebody advice me?
Last updated
Mohsin said:
Hi. You have done it wrong. You need to use
onSend
and not::onSend
. Also, you have not added this function to the layout instead of the page. That’s why you a handler not found error. So, goto CMS tab -> Pages -> Your Contact Page and then click on the Code section and paste in the onSend function as I had given in the first post.conprefor16116 said:
Could anybody help me with contact form on [HSE KZ]: http://hse.kz/contacts.
I don't understand what i have to do for create this form handler.
As mentioned by Mohsin, I have done:
- Adding data-request string to <form ...>
- Creating partial, where form is included
- Add to layout-> default.htm -> code But it doesn't work, it shows the error messages such as "Couldn't found onSend..." or error " ...not found ... System\Models\MailSettings::get('sender_email');"
Could somebody advice me?
Hi Mohsin, Thanks a lot for fast response. i done as you told.
But i still not able to send mails via contact form.
Could you look at https://goo.gl/9JnEiW please ?
Last updated
conprefor16116 said:
Mohsin said:
Hi. You have done it wrong. You need to use
onSend
and not::onSend
. Also, you have not added this function to the layout instead of the page. That’s why you a handler not found error. So, goto CMS tab -> Pages -> Your Contact Page and then click on the Code section and paste in the onSend function as I had given in the first post.conprefor16116 said:
Could anybody help me with contact form on [HSE KZ]: http://hse.kz/contacts.
I don't understand what i have to do for create this form handler.
As mentioned by Mohsin, I have done:
- Adding data-request string to <form ...>
- Creating partial, where form is included
- Add to layout-> default.htm -> code But it doesn't work, it shows the error messages such as "Couldn't found onSend..." or error " ...not found ... System\Models\MailSettings::get('sender_email');"
Could somebody advice me?
Hi Mohsin, Thanks a lot for fast response. i done as you told.
But i still not able to send mails via contact form.
Could you look at https://goo.gl/9JnEiW please ?
Whoa… The code is messed up. Divs inside labels aah my eyes hurt. Divs should not go inside label as label is an inline element, see this.
In any case, I tested the code and it works fine. I think the problem is that you have used my mail template screenshot as is i.e. Message: {{message}}
. Kindly read my first comment, I had mentioned a minor update saying that message is reserved word and msg should be used instead.
Mohsin,
I really appreciate Your attentionI am not so close with W3 and HTML5 docs as you, but i will learn this information.
Regarding labels and divs, i used the template http://goo.gl/M1yxOo (zBlueCar) As you, I'm found a few issues too, but my friend who owns [hse kz] like this template design.
To sum up, you are great! Thanks.
Last updated
conprefor16116 said:
Mohsin,
I really appreciate Your attentionI am not so close with W3 and HTML5 docs as you, but i will learn this information.
Regarding labels and divs, i used the template http://goo.gl/M1yxOo (zBlueCar) As you, I'm found a few issues too, but my friend who owns [hse kz] like this template design.
To sum up, you are great! Thanks.
Hi. Thanks for the appreciation. I would like to know, have you solved the issue yet? If not I can use this template to build the contact form again, zip it and send back to you with working code. Let me know.
Hi. Thanks for the appreciation. I would like to know, have you solved the issue yet? If not I can use this template to build the contact form again, zip it and send back to you with working code. Let me know.
Good evening Mohsin,
Yes, i've fixed it with your advisement. I got to thinking. Is it possible to send attachments?
I mean case if i add in the form <input type="file" ...>. In this case how it is possible check file properties (e.g. size, format, etc.) and attach to email.
I just think (imagine) about this, i don't have this task.
Last updated