Contact form is not working, how to debug this?

At first, I tried to make this using AjaxForm but that was not working, after that, I tried without AjaxForm but it’s not working. Just reloading the page.
How can I figure out the issue?

[[!FormIt?
    &hooks=`email,redirect`
    &form=`contact_form`
    &redirectTo=`7`
    &emailSubject=`New Case from`
    &emailTo=`cybertech537@gmail.com`
    &validationErrorMessage=`The form contains errors!`
    &successMessage=`Message sent successfully`
    &validate=`nospam:blank,
        email:email:required`
]] 
[[!+fi.validation_error_message:notempty=`<p>[[!+fi.validation_error_message]]</p>`]]		
<form action="[[~[[*id]]]]" method="post" class="">
    <input type="hidden" name="nospam" value="" />
    
    <div class="consult-form">
        <div class="">
            <input type="text" name="fullname" placeholder="Name*" value="[[!+fi.fullname]]" required>
            <p class="error">[[!fi.error.fullname]]</p>
        </div>
        <div class="">
            <input type="text" name="phone" placeholder="Phone*" value="[[!+fi.phone]]" required>
            <p class="error">[[!fi.error.phone]]</p>
        </div>
        <div class="">
            <input type="email" name="email" placeholder="E-mail*" value="[[!+fi.email]]" required>
            <p class="error">[[!fi.error.email]]</p>
        </div>
        <div class="">
            <input type="text" name="subject" placeholder="Subject" value="[[!+fi.subject]]">
            <p class="error">[[!fi.error.subject]]</p>
        </div>
        <div class="col-span-2">
            <textarea name="message" placeholder="Briefly describe your legal situation*" required>[[!+fi.message]]</textarea>
            <p class="error">[[!fi.error.message]]</p>
        </div>
    </div>
		
    <button name="send" type="submit" class="FormButton FormSubmit"><span>SUBMIT</span></button>
    
    [[+fi.success:is=`1`:then=`
        <div class="alert alert-success">[[+fi.successMessage]]</div>
    `]]
    [[+fi.validation_error:is=`1`:then=`
        <div class="alert alert-danger">[[+fi.validation_error_message]]</div>
    `]]
</form>

The only thing I can see that is wrong, is that some of the placeholder are missing the +[[!fi.error.fullname]] instead of [[!+fi.error.fullname]]. (But this shouldn’t prevent the form from working.)

  • Are there any errors in the MODX error log?
  • Does it redirect if you remove the email hook?

I downloaded the log file and it has lots of errors.
How can I solve these?


Yes, It redirects but the mail doesn’t go.

The error in the printscreen you posted can be fixed by changing the “Resource Alias” of either the resource with ID = 80 or ID = 216, as these seem to have the same value.


Try to explicitly set the emailFrom property.

[[!FormIt?
   ...
   &emailFrom=`from@yourdomain.com`
]]

If you have a field with name="email", FormIt uses the value of this field as the from address, which usually creates a problem.

Still it’s not working.

[[!FormIt?
  &emailTpl=`MyEmailChunk`
  &hooks=`redirect`
  &redirectTo=`7`
  &emailFrom=`info@internetlava.com`
  &emailTo=`cybertech537@gmail.com`
  &validate=`nospam:blank,
      email:email:required`
]]

Maybe put the email hook back in.

Yes, It works now. Made my day.

1 Like

@halftrainedharry

Hi, I need your assistance.

  • I need to send the user email to multiple addresses. I did it like &emailTo=`cybertech537@gmail.com,mdjahidulislam712@gmail.com and it’s working. I don’t know whether it’s the correct way or not

  • Besides, the user/visitor will receive a confirmation email that the administrator got his mail and will contact him soon.
    For example:

Yes, that’s the correct way. There exist also other properties that you could use like emailBCC or emailCC.
Take a look a the documentation:

https://docs.modx.com/current/en/extras/formit/formit.hooks/email


There is the “FormItAutoResponder” hook for that:

https://docs.modx.com/current/en/extras/formit/formit.hooks/formitautoresponder

Thanks a ton, brother. :green_heart: