• Create a form using modx revo. Feedback form on MODX Revo using Formit with an unusual captcha. Create a chunk sentEmailTpl

    06-08-2014 22:30:00 3886 Comments ollserg & MaxWeb for you

    ABOUT We very quickly create a feedback form on a website running CMF MODX revo using the FormIt package.
    I will not describe the process of installing packages on MODX revo in detail in this post due to its simplicity and the large amount of material on this topic on the Internet. Let me just remind you of the sequence of actions:
    <Система> - <Управление пакетами> - <Загрузить дополнения> - <Поиск>(enter - FormIt)


    N press<Загрузить>and then<Установить>
    D Next, let's create a new chunk and call it




    and paste the following code:















    WITH create a chunk sendEmailTpl It describes what information to send by email and insert the code there:

    From:


    Telephone:



    Message:

    Here:
    - sender's name
    - sender's phone number
    - sender's email
    - a message written by the sender on the website

    D Next, we will create a page with a message about successful submission and thanks for the fact that the user sent a message through the feedback form.
    For example:

    Thank you for sending your letter!
    Your letter has been sent successfully.
    Our specialist will answer you as soon as possible.

    N and set up a redirect for this page by its ID.


    Not we forget to change the value of the &redirectTo=`178` parameter in the place where the FormIt snippet is called (in the chunk code

    ), where the correct resource ID should be passed. And also &emailTo=` [email protected]` - naturally to your box.

    I have this page ID - 178. We will use this ID below when calling FormIt.

    Let's take a closer look at the FormIt add-on call block:

    Here:
    The first parameter is hooks. Hooks are FormIt add-on scripts.
    In our case, we have two of them - email is responsible for sending the email itself,
    and redirect - sends the user to a page with thanks for the contact;
    emailTpl - a template for a letter sent on the site. Above we created and edited it;
    emailSubject - subject of letters that will come from the site;
    redirectTo - ID of the page that will be shown to the user after
    how he sent a message through the feedback form. We created it earlier;
    emailTo - email address where emails from the site will be sent.

    We need to add a few CSS rules to make our form look more attractive.
    input, label, textarea( display: block; )
    input, textarea( margin: 0 0 10px 0; border: 1px solid #ccc; padding: 5px; )
    input.submit_button( background-color: #43A52B; border: 1px solid #358222; padding: 5px 10px; border-radius: 3px; font: 13px Arial, Verdana, Tahoma, sans-serif; color: #fff; cursor: pointer ; )
    input.submit_button:hover( background-color: #358222; )
    span.required
    span.error( color: #ff0000; )
    span.required(font-size: 18px; )
    span.error(font-size: 11px; )

    On on the MODX revo website it looks like this:


    AND The result of our work was the MODX revo feedback form using the FormIt package. Not happy with the appearance? Edit the CSS code or write your own. That's all. Order topics for articles. If there are difficulties, we will help you solve them.

    Comments
    asdfgzx replied on Fri, 08/08/2014 - 11:50

    THANK YOU
    Simple and clear
    I installed it on my website and everything worked immediately.
    The feedback form is good, but the design will need to be improved!

    answer
    Slavik replied on Wed, 29/10/2014 - 17:20

    IT DIDN'T WORK
    I installed everything and configured everything; when sending, it goes to the thank you page, but nothing arrived by email (:

    answer
    Ayat replied on Wed, 03/12/2014 - 22:54

    THANK YOU
    Thanks for the detailed description. Everything works!

    answer
    Maxim replied on Mon, 08/12/2014 - 16:13

    ERROR
    Good afternoon, the error is this in the log:

    can you tell me how to fix it?

    answer
    Maxim replied on Mon, 08/12/2014 - 16:14

    ERROR
    Good afternoon, could you please tell me what is the error?

    (ERROR @ /modx/connectors/modx.config.js.php) Error caching lexicon topic lexicon/ru/core/resource

    answer
    ollserg replied on Tue, 23/12/2014 - 20:41

    SORRY FOR THE LONG REPLY
    This error, in my opinion, occurs when using a gallery.
    Experiment with gallery and engine versions! This is rather the question.

    answer
    Mikhail replied on Tue, 03/02/2015 - 12:17

    VALIDATION
    If a form element fails validation, the screen moves up. How to leave it in place of the form?

    answer
    vita replied on Thu, 28/07/2016 - 17:26

    VALIDATION
    This is done very simply. Only you cannot leave it in place, you need to scroll to it. To do this, you need to create an identifier (id) for the desired element and specify it in the action parameter via #:

    Thanks for the answer -itchief.ru- I took it from there.

    answer
    ollserg replied on Wed, 04/02/2015 - 16:33

    I WOULD LIKE TO SEE.
    Check the layout. It's clearly about her.
    Well, preferably visually, i.e. screenshot

    answer
    Andrey replied on Mon, 02/03/2015 - 13:08

    FROM LOCAL SERVER
    I'm sorry, but will this form work on a local server with network access (Open Server)? I tried to send from this form, but nothing came.
    The server has access to the network - packages from external repositories are installed from the modx admin panel.

    answer
    ollserg replied on Tue, 03/03/2015 - 20:59

    ON THE LOCAL SERVER FORM
    By definition, the form cannot work on a local server. Only on hosting.

    answer
    ollserg replied on Tue, 03/03/2015 - 21:03

    AND SITE DEVELOPMENT ON
    And website development on MODX takes place online on hosting much more conveniently.

    answer
    Denis replied on Thu, 16/04/2015 - 22:11

    FORMIT
    Good afternoon
    Everything works with your form! Thank you!
    but I tried to adapt it to mine and nothing works.
    Here is the code, please look! Thank you!
    For example, I changed the email to [email protected]





    answer
    ollserg replied on Fri, 17/04/2015 - 11:07

    THIS FEEDBACK FORM CODE CANNOT WORK!
    This is not an adaptation! You have removed all functionality! Re-read the article carefully and you will understand.
    Here I have described everything in detail, but if it still doesn’t work out, you can contact us through the “order” form on this site.

    answer
    Denis replied on Mon, 20/04/2015 - 17:56

    FORMIT POP-UP WINDOW
    Thank you! figured it out!
    Do you have a lesson on how to make it so that when you click the “send” button, a message about successful sending appears in a pop-up window, and not on a new page?

    answer
    ollserg replied on Thu, 23/04/2015 - 14:56

    MODAL WINDOW
    Use it as a pop-up on your website. There are many implementation methods, one example:

    Open window 1


    Well, the CSS for this code.

    answer
    Alexey replied on Sun, 05/31/2015 - 16:09

    MODAL WINDOW
    needs to be written in the html template, but the value of #win1 is unknown to it? Should I ask it somewhere?


    Thank you.

    answer
    Alexey replied on Sun, 31/05/2015 - 16:17

    MODAL WINDOW
    Please clarify, where should the #win1 parameter in the form chunk be written so that in the html template the link understands what exactly needs to be called? Maybe I misunderstood something, but the line

    needs to be written in the html template, but the value of win1 is unknown to it? Should I ask it somewhere?
    I’ve only been familiar with modx for 3 days, please, like everything described above, explain it in a simple way.
    Thank you.

    answer
    ollserg replied on Mon, 01/06/2015 - 12:28

    HTML CODE OF THE MODAL WINDOW


    answer
    Alex replied on Tue, 07/07/2015 - 10:18

    NO LETTER

    Yours worked, the letter arrived.


    I changed the fields to those that were needed and, alas, the letter stopped coming.


    here is the code





    answer
    ollserg replied on Wed, 08/07/2015 - 13:09

    Q!FORMIT? DESCRIBE TEXT AND EMAIL
    In!FormIt? you need a type description - &validate=`email:email:required,text:required:stripTags`

    answer
    Victor replied on Mon, 19/10/2015 - 14:03

    MESSAGE SUBJECT IN THE FORMIT FEEDBACK FORM
    Good day.
    I use "&emailSubject=`Letter from the site https://site/" - the letter is not sent, the form returns to the state where there is an error in the field.
    .
    It is clear that it does not understand the Cyrillic encoding, but where to look?
    Please tell me what it could be. cause.
    Thank you.

    answer
    ollserg replied on Tue, 20/10/2015 - 22:47

    APACHE AND PHP VERSIONS
    The first thing I think you should pay attention to in your case is the versions of Apache and PHP on your server.

    answer
    AlexP replied on Thu, 29/10/2015 - 14:15

    PLACEHOLDER
    The placeholder is trimmed..
    I wanted to make “Your name” inside the input and style the css But for some reason the code after value="" placeholder="Your name) is cut" - обрезается!}
    Thank you

    answer
    ollserg replied on Thu, 29/10/2015 - 20:01

    ALL CSS CONNECTED MUST BE CHECKED
    Trimming the "placeholder" occurs precisely because of the layout

    answer
    Roman replied on Fri, 27/11/2015 - 13:43

    FORMIT AND PROBLEMS

    There is a big disadvantage to Fornit or its documentation. Here I have a beautiful feedback pop-up window, but it is not created by a separate document, but pops up using jquery! So Formit doesn’t work with it.. And I can’t figure out how to set it up! Maybe you've encountered something similar.

    answer
    ollserg replied on Tue, 01/12/2015 - 23:23

    AJAXFORM USE FOR POPUP FEEDBACK
    FormIt does not know how to create ajax out of the box... To it, i.e. FormIt needs to be written as an add-on... or AjaxForm used, which will be the best solution for popup feedback.

    answer
    andreev888 replied on Sat, 05/12/2015 - 22:26

    SOMETHING IS NOT OKAY
    People, tell me, the instructions seem to be the most accessible of all that I have seen, I did everything according to the instructions, but I don’t see the form on the site at all... neither a hook, nor a comma... It just doesn’t appear... Where can I look?

    answer
    ollserg replied on Sun, 06/12/2015 - 23:37

    MODX REVOLUTION - CLEAR CACHE
    And if in the Menu - Site and Update site (Clear site cache) This is the first thing that comes to mind. Well, everything is simple, re-read the post once or twice and you will succeed!!!

    answer
    Evil replied on Fri, 18/12/2015 - 07:00

    ANGER
    You're tired of copying the same articles! Come up with something of your own or at least change the code in the article!

    answer
    ollserg replied on Fri, 18/12/2015 - 14:28

    READERS HAVE ALREADY TRIED TO CHANGE THE CODE OF THIS FORM
    They had questions related to the inoperability of this code.
    You can read it in the comments above.
    Another question is that many (there are no exact statistics) thoughtlessly copy and paste the code of this article onto their websites without even reading it carefully. I deliberately copied the feedback form code from my website and indicated in the article the places in the code that need to be changed to my own. And how many letters from websites were sent to my email until I corrected the address in the code?! There were no hundreds of them, just dozens.

    answer
    svbel replied on Thu, 02/06/2016 - 10:11

    ERROR WHEN SENDING MAIL
    What does the message "An error occurred while trying to send mail. The mail function cannot be started."?

    answer
    ollserg replied on Thu, 02/06/2016 - 10:54

    THE MAIL FUNCTION CANNOT BE STARTED.
    There can be many reasons. Look at the logs, does the mail domain and mail specified in FormIt exist and work normally?
    Ask a question to your hosting provider's support. In general, there is no clear answer to your question.

    answer
    Denis replied on Wed, 15/06/2016 - 15:53

    LETTERS DO NOT ARRIVE IN EMAIL
    Good afternoon I made a form according to your description, everything works, it moves to the thank you page, but nothing arrives by email.
    Hosted website. In theory, everything is normal in the code

    Tell me, what is the problem? Thank you!

    answer
    ollserg replied on Fri, 17/06/2016 - 12:17

    MODX FEEDBACK FORM IS 100% CORRECT. FOLLOW INSTRUCTIONS.
    Please read the article carefully. Pay attention to the chunk

    in particular line No. 4 - &emailTo=` [email protected]` [email protected] Are you sure you replaced it with your email?
    Enter the details of the mail servers yandex.ru, gmail.com or whatever you have. If this worked, then the problem is with your mail on the hosting where your site is located. Contacting your hosting provider's support team will help you.

    answer
    Denis replied on Tue, 06/28/2016 - 15:05

    MAIL.RU POST
    Good afternoon I noticed a problem that if you enter mail.ru email into the form (others: Yandex, Google, etc. work) to contact you, then this message will not be sent to the site administrator’s email.
    Has anyone encountered this? Maybe Formit has a restriction for emails?

    Thanks in advance!

    answer
    Timothygreby replied on Tue, 11/10/2016 - 13:40

    ORGAZM-ONLINESOT
    I am also concerned about this issue. Tell me where can I read about this?

    orgazm-online.org

    answer
    SpS replied on Tue, 18/10/2016 - 15:39

    INSTALLING SAMS2 ON FREEBSD
    Installing SAMS2 on FreeBSD 10.1, Squid 3.4 with NTLM authorization

    http://www.grayfort.com/2015/01/sams2-freebsd-101-squid-34-ntlm.html

    answer
    lomaster replied on Tue, 08/11/2016 - 02:35

    REMONTOKNA.COM.UA
    It is becoming increasingly popular to create interactive websites using AJAX technology. Indeed, why force the user to reload the entire page if there is an opportunity not to do this. This is especially true for mobile devices. Many sites use a feedback form to communicate with the client. Let's take a regular form and make it Ajax.

    answer
    MaryMJ replied on Thu, 12/15/2016 - 20:27

    ABOUT ADVERTISEMENT ON YOUR WEBSITE
    Hello! My name is MaryMarkova, our company needs to advertise on your website. What are your prices? Thank you. Best regards, Mary.

    answer
    Rachelboymn replied on Fri, 23/12/2016 - 18:27

    XRUMER 16.0 IS THE BEST SEO SOFTWARE
    The new XRumer 16.0 - revolution in online promotion: artificial intelligence will help you to attract customers so effectively, more than ever!


    We only have one page left that we haven't redone yet. This is the page Contacts. Here, in addition to contact information, we will have a feedback form. In MODx there is a special snippet for creating such a form - eForm. Let's first look at what a feedback form can consist of.

    1. First of all, this is the form itself with input fields Name, Postal address, Message topics and himself Messages. To protect against spam, you should add a captcha - a form for entering the code from the generated image. It is also necessary to enable verification of the correctness of information entered.

    2. Notifying the visitor about sending a message.

    3. The form of the sent message that will be sent by email.

    Create a chunk with a feedback form template

    Before creating a chunk with a template for a feedback form, let's study the code that describes this form in our template. Open the file in Notepad++ contact.html which is in the folder C:/xampp/htdocs/site/www/assets/templates/templatemo_250_chess/. These will be the lines with 135 By 159 inclusive. As you can see, this is a container with id="contact_form", which is where our form is located. Using this code as a basis, we create a new chunk form-tpl and add the placeholders we need:

    Feedback


    [+validationmessage+]







    Enter this code:





    Where [+validationmessage+]- is responsible for displaying error messages when submitting the form.
    action="[~[*id*]~]- indicates that the form handler will be the page on which the snippet is called. Instead of [~[*id*]~] MODx will substitute the URL of the current document.
    specifies the form ID that we will specify when calling the snippet.
    label accesskey- sets access to form elements using hotkeys.
    eform="Email:email:1"- describes the field for entering a postal address, indicates the type of data to be entered and makes this field mandatory. In general, the template for filling out this parameter is as follows: eform="[field description]:[type of input data]:[whether the field is required]:[input error message]:[input validation rule]" . But we only need three values. Similarly to this parameter, eform="Name::1" is filled in.
    [+verimageurl+] is responsible for displaying the captcha.

    Create a chunk notifying the visitor that a message has been sent

    Creating a chunk thank-tpl

    Thank you for using the feedback form on our website.

    Your message will be reviewed as soon as possible, and if it requires a response, you will definitely receive it.


    Sent information:



    • Your name:[+author+]

    • Your email:[+email+]

    • Message text:[+text+]

    Create a chunk with the sent message form

    Creating a chunk report-tpl and place the following code in its contents:

    This message was submitted by a visitor named [+author+] using the feedback form.






    Name:[+author+]
    Email::[+email+]
    Message:[+text+]

    In this chunk, as in the previous one, all information entered by the user is transmitted using placeholders of the form [+author+]. In this case, the name of each placeholder coincides with the value of the “name” attribute of the corresponding field in the chunk with the feedback form (name="author", name="email" name="text").

    Create a chunk with a call to the feedback form

    Create a chunk with a name form and put the structure there:

    [!eForm? &formid=`Send` &tpl=`form-tpl` &to=` [email protected],[email protected],[email protected]` &mailselector=`otdel` &report=`report-tpl` &thankyou=`thank-tpl` &vericode=`1` &subject=`Message from my website`!]

    Where &formid=`Send`- form identifier, which we specified in the form-tpl chunk
    &tpl=`form-tpl`- template for the feedback form
    &to=` [email protected],[email protected],[email protected]` - Email address for sending information
    &mailselector=`otdel`- sets the form field that will be used when selecting a single address from a list of addresses separated by a comma (,) in the parameter &to. In our case, this is a drop-down list

    [[!+fi.error.name]]
    [[!+fi.error.phone]]
    [[!+fi.error.email]]
    [[!+fi.error.message]]

    Code analysis, going from top to bottom:

    &hooks - various hooks are added here, including custom ones: in our case, 2 standard ones: span - simple anti-spam protection and email - mandatory, for sending data to a mailbox. I talk about the rest of the hooks in sufficient detail in the video.

    &emailTpl - a chunk with the design of a letter, has the following code:

    From: [[+name]]

    Phone: [[+phone]]

    E-mail: [[+email]]

    Message: [[+message]]

    &emailTo - email address where forms are sent, in this case the system setting (key) ++emailsender is specified

    &emailSubject - subject of the email being sent

    &validate - we specify mandatory fields to fill in and often fields to protect against spam

    &successMessage - message after successful sending

    I won’t analyze the form code; if you are interested, watch the video and read the documentation: docs.modx.com/extras/revo/formit

    Attaching files to a form

    In order to be able to attach and send attachments, you need to write in the form tag

    Enctype="multipart/form-data"

    and accordingly add fields for attaching a file

    [[!+fi.error.upload]]

    Processing checkboxes and options

    Multiple forms on one page

    Just write in the calls of each form

    &submitVar=`form name in English`

    Each form has its own name.

    Fighting spam

    Whatever you say, you will definitely encounter spam - the most effective way to combat it is, you can also try.

    Almost all commercial sites have a contact page, which contains a contact form through which users can write to the site administration. Today we will look at how to quickly create a contact form. We will implement the feedback form using the package Formit in conjunction with the package AjaxForm, install them if you do not have them installed.

    Creation of a feedback form on MODX Revo with permission to process personal data in accordance with Law No. 152-FZ “On Personal Data” dated July 27, 2006.

    First of all, we create a chunk in which the form itself will be stored, let it be a “kontact-form” chunk and place the code of the standard form in it, I mainly make websites using bootstrap, so I’ll take a standard template slightly modified, its static code will be like this:

    User Agreement

    Your appearance will be different, since my form is stylized for the project, I don’t see any point in posting css styles.

    Here you can see other forms getbootstrap.com/css/#forms

    Now let’s convert the code into dynamic, taking into account the syntax Formit And AjaxForm, we get the following.

    [[+fi.error.name]]
    [[+fi.error.email]]
    [[+fi.error.pfone]]
    [[+fi.error.message]]

    By checking this box, I give my consent to the processing of my personal data in accordance with Law No. 152-FZ “On Personal Data” dated July 27, 2006 and accept the terms of the User Agreement

    [[+fi.success:is=`1`:then=`
    [[+fi.successMessage]]
    `]] [[+fi.validation_error:is=`1`:then=`
    [[+fi.validation_error_message]]
    `]]

    Now let’s create another chunk that will generate a letter, let’s call it tpl-kontact-form with the following content:

    Name: [[+name]]

    Email: [[+email]]

    Phone: [[+pfone]]

    Message: [[+message]]

    Well, it became possible to draw a conclusion in the right place:

    [[!AjaxForm? &snippet=`FormIt` &form=`kontact-form` &emailTpl=`tpl-kontact-form` &hooks=`spam,email` &emailSubject=`Message from the site [[++site_url]]` &emailTo=` [email protected]` &validate=`name:required,email:required` &validationErrorMessage=`The form contains errors!` &successMessage=`Message sent successfully!` ]]

    Don't forget to change the value emailTo to your email.

    Component documentation:

    1. FormItdocs.modx.com/extras/revo/formit
    2. AjaxFormdocs.modx.pro/components/ajaxform

    That's basically all!

    To create a form on Modx without spam, you need to create it with additional invisible fields:

    1. Download and install the Ajaxform and Formit components

    2. The form is called very simply, you have to figure it out

    [[!AjaxForm? &snippet=`FormIt` &form=`tpl.AjaxForm..ru ` &emailTo=`info@site` &validate=`name:required,email:required,message:required,work-email:blank` &validationErrorMessage=`The form contains errors !` &successMessage=`Thanks for your application! We will contact you shortly.` &emailTpl=`mailtpl` ]]

    Or through the Fenom template engine, like this:

    ($_modx->runSnippet("!AjaxForm", [ "snippet" => "FormIt", "form" => "tpl.AjaxForm.example", "hooks" => "email,spam" "emailFrom" => " [email protected]", "emailSubject" => "Application from the site daruse.ru", "emailTo" => " [email protected]", "validate" => "name:required,email:required,message:required,work-email:blank", "validationErrorMessage" => "The form contains errors!", "successMessage" => "Thank you for your application! We will contact you shortly.", "emailTpl" => "mailtpl", ]))

    Description of parameters:

    • snippet - snippet for processing AjaxForm, set Formit - it just sends letters
    • form - form design chunk, the default one
    • hooks - anti-spam hooks
    • emailFrom - the address from which the letter comes
    • emailTo - the address to which the letter is sent
    • validate - validation, there are also two invisible fields
    • validationErrorMessage - message that will be displayed if fields are not entered successfully
    • successMessage - message that will be displayed when a letter is sent successfully
    • emailTpl - chunk in which the template for an incoming email is stored (read about it below)

    3. After that, go to our form design chunk, in this case it is tpl.AjaxForm.example and add the following two fields after the form tag.

    ...

    Now your form should not contain spam, due to two new fields.

    4. Appearance of an incoming letter

    By default, a letter arrives in the mail without any formatting in a not very readable format. So let's formalize our letter a little using an example.

    A letter template is a simple chunk that we specify in the parameter emailTpl, everything is very simple here, I’ll write an example of the design. If you have any questions, write in the comments.

    mailtpl:

    On the website [[++site_url]] left a request.

    [[+name:notempty=`

    Name: [[+name]]

    `]] [[+email:notempty=`

    Email: [[+email]]

    `]] [[+message:notempty=`

    Message: [[+message]]

    `]]

    Please contact him as soon as possible.

    Do not reply to this email as it is automatic.

    Read about creating and protecting against spam.