Can't get FormIt to send form

Hi Guys,

I’m having trouble getting a contact form to run using formit.

I have setup the standard form from this link: link

When i submit a form on the contact page, it just refreshes the page and show the form with no feedback or redirect.

I’ve tried stripping validation, spam and recaptcha out of the form but still can’t get anywhere.

I was thinking maybe formit could be installed in the wrong directory on the server based on the config files as this has been a problem in the past but other extensions work just fine.

I’ve setup G suite smtp relay in modx settings and it works when i test it with Quick Mail.

Any ideas?

Please see the code below:

[[!FormIt?
&hooks=email,redirect
&emailTpl=MyEmailChunk
&emailTo=neil@verdespaces.co.uk
&redirectTo=1
]]

Contact Form

[[!+fi.validation_error_message:notempty=<p>[[!+fi.validation_error_message]]</p>]]

<label for="name">
    Name:
    <span class="error">[[!+fi.error.name]]</span>
</label>
<input type="text" name="name" id="name" value="[[!+fi.name]]" />

<label for="email">
    Email:
    <span class="error">[[!+fi.error.email]]</span>
</label>
<input type="text" name="email" id="email" value="[[!+fi.email]]" />

<label for="subject">
    Subject:
    <span class="error">[[!+fi.error.subject]]</span>
</label>
<input type="text" name="subject" id="subject" value="[[!+fi.subject]]" />

<label for="text">
    Message:
    <span class="error">[[!+fi.error.text]]</span>
</label>
<textarea name="text" id="text" cols="55" rows="7" value="[[!+fi.text]]">[[!+fi.text]]</textarea>

<label>
    Numbers:[[+fi.error.numbers]]
    <select name="numbers" value="[[!+fi.numbers]]">
        <option value="">Select an option...</option>
        <option value="one" [[!+fi.numbers:FormItIsSelected=`one`]]>One</option>
        <option value="two" [[!+fi.numbers:FormItIsSelected=`two`]]>Two</option>
        <option value="three" [[!+fi.numbers:FormItIsSelected=`three`]]>Three</option>
    </select>
</label>

<label>
    Colors:[[!+fi.error.colors]]
    <input type="hidden" name="colors[]" value="" />
</label>
<ul>
  <li>
    <label><input type="checkbox" name="colors[]" value="red" [[!+fi.colors:FormItIsChecked=`red`]] /> Red</label>
  </li>
  <li>
    <label><input type="checkbox" name="colors[]" value="blue" [[!+fi.colors:FormItIsChecked=`blue`]] /> Blue</label>
  </li>
  <li>
    <label><input type="checkbox" name="colors[]" value="green" [[!+fi.colors:FormItIsChecked=`green`]] /> Green</label>
  </li>
</ul>

<br class="clear" />


<br class="clear" />

<div class="form-buttons">
    <input type="submit" value="Send Contact Inquiry" />
</div>

MyEmailchunk:

This is the Formit Email Chunk.


[[+name]] ([[+email]]) Wrote:

[[+text]]

Does it work with only the redirect hook?

[[!FormIt?
   &hooks=`redirect`
   &redirectTo=`1`
]]

Are there any errors in the MODX error log?

When i tried your hook it redirected to the homepage (1). So that worked. No errors for this in the log.

Does it create any errors in the error log when you send the form with the email hook? A message like “An error occurred while trying to send the email.”?

As there seems to be a problem with sending emails you could try this:
Create a new snippet myemailhook with this code: (Change the email address in the code to your email address.)

<?php
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY,'test message');
$modx->mail->set(modMail::MAIL_FROM,$modx->getOption('emailsender'));
$modx->mail->set(modMail::MAIL_FROM_NAME,$modx->getOption('site_name'));
$modx->mail->set(modMail::MAIL_SENDER,$modx->getOption('emailsender'));
$modx->mail->set(modMail::MAIL_SUBJECT,'test email');
$modx->mail->address('to','your_email_address@domain.com');
$modx->mail->setHTML(false);
if (!$modx->mail->send()) {
    $modx->log(modX::LOG_LEVEL_ERROR,'Could not send email!');
}
$modx->mail->reset();
return true;

Then add this snippet as a hook to FormIt

[[!FormIt?
   &hooks=`myemailhook,redirect`
   &redirectTo=`1`
]]

Does that work?

Yes that worked! Should i use this instead do you think?

No errors in the error_log on the server no

This is very strange. The email hook basically does more or less the same. Maybe you could try to do some debugging to find out where the code fails, or reinstall the package and see if that helps.

As a last resort you can write your own snippet to send the email. Read the part about custom hooks in the documentation. Use

$email = $hook->getValue('email');
$allFormFields = $hook->getValues();

to read the values from the form and $modx->getChunk('MyEmailChunk',$array_with_values) to generate the message from a chunk.

Hey,

I’ve tried some debugging on the form. When i strip the form fields back to just the name field, the email sends using the ‘MyEmailChunk’ chunk. It includes the name input into the form.

The emails looks like this: mike [[+email]] [[+text]]

When i add fields into the form for email and text, it doesn’t come through.

This is the code for the form. I’m trying to find an error in the code but i can’t see anything. Any thouhgts?

[[!FormIt?
&hooks=email
&emailTpl=MyEmailChunk2
&emailTo=neil@verdespaces.co.uk
]]

Contact Form

[[!+fi.validation_error_message:notempty=<p>[[!+fi.validation_error_message]]</p>]]

<label for="name">
    Name:
    <span class="error">[[!+fi.error.name]]</span>
</label>
<input type="text" name="name" id="name" value="[[!+fi.name]]" />

<label for="email">
    Email:
    <span class="error">[[!+fi.error.name]]</span>
</label>
<input type="text" name="email" id="email" value="[[!+fi.name]]" />

<label for="text">
    Text:
    <span class="error">[[!+fi.error.name]]</span>
</label>
<input type="text" name="text" id="text" value="[[!+fi.name]]" />

<div class="form-buttons">
    <input type="submit" value="Send Contact Inquiry" />
</div>

this is the chunk ‘MyEmailChunk2’:

[[+name]]
[[+email]]
[[+text]]

Try adding the property &emailFrom in your call to FormIt (and set it to a value different from &emailTo).

[[!FormIt?
   &hooks=`email`
   &emailFrom=`from@domain.com`
   &emailTpl=`MyEmailChunk2`
   &emailTo=`to@domain.com`
]]

I believe otherwise the code tries to use the value from the form field email as the from address.

Sorry when i ran the test before i actually had your previous test still in the formit call:

[[!FormIt?
&hooks=myemailhook,redirect
&redirectTo=1
]]

Still no joy in getting formit to send. I’ve tried removing the extension and reinstalling it but no luck.

I’ve just finished building a new site in modx on the same server and the contact form sends just fine. I think i’m going to install a fresh copy of Modx on another sever account and migrate it over. Hopefully that will fix it! i’ll keep you updated.

I’ve still not managed to get this working. I tried reinstalling modx on the server and just setting up the contact form on its own from scratch. Doesn’t work. I don’t understand why because on the same server on a different account, another website works without a problem with the same setup using goggle servers.

I’ve deleted the account on the server and am setting up a fresh Cpanel account now for it to see if that helps.

Maybe i’m missing something that can easily be fixed but i’m not that experienced with debugging things like this.

Finally it works. Deleting the Cpanel account in WHM and starting from scratch worked. I can’t give any more details as to why this is but it worked in the end. Thanks for your help