Jump to content

FrontendContact - Module for creating one or more contact forms on the frontend


Recommended Posts

I guess that something stops the sending process, but without TracyDebugger we get no information whats going on. You can take a look into the log files if you find something.

Another try would be to remove the creation of the page for testing purpose - let only the mail function inside the isValid() method and see what happens.

The code seems to be OK


  • Like 1
Link to comment
Share on other sites

<?php namespace Processwire;
$form = new \FrontendForms\Form('myForm');

$firstname = new \FrontendForms\InputText('scf_firstname');
$lastname = new \FrontendForms\InputText('scf_lastname');
$phone = new \FrontendForms\InputText('scf_phone');
$email = new \FrontendForms\InputText('scf_email');
$legalservice = new \FrontendForms\Select('scf_legalservice');
// Add options dynamically based on existing pages
$legalservices = wire('pages')->find('template=legal_service');
foreach ($legalservices as $service) {
$legalservice->addOption($service->title, $service->id);
$message = new \FrontendForms\Textarea('scf_message');

$button = new \FrontendForms\Button('submit');
$button->setAttribute('value', $fields->get('label_send')->label);

    $p = new Page();
    $p->template = 'contact_inquiry';
    $p->parent = wire('pages')->get('template=contact');
    $p->title = $form->getValue('scf_firstname') . ' ' . $form->getValue('scf_lastname');
    $p->scf_firstname = $form->getValue('scf_firstname');
    $p->scf_lastname = $form->getValue('scf_lastname');
    $p->scf_phone = $form->getValue('scf_phone');
    $p->scf_email = $form->getValue('scf_email');
    $p->scf_legalservice = $form->getValue('scf_legalservice');
    $p->scf_message = $form->getValue('scf_message');
    // Set the scf_date field to the current date and time with the correct timezone
    $dateTime = new DateTime('now', new DateTimeZone('Europe/Stockholm'));
    $p->scf_date = $dateTime->format('U'); // 'U' format returns the Unix timestamp
    $m = wireMail();
    $m->to('info@...'); // please change it
    $m->subject('Nytt ärende');
    $messageBody .= "<strong>{$fields->get('scf_firstname')->label}:</strong> " . $form->getValue('scf_firstname') . "<br>";
    $messageBody .= "<strong>{$fields->get('scf_lastname')->label}:</strong> " . $form->getValue('scf_lastname') . "<br>";
    $messageBody .= "<strong>{$fields->get('scf_phone')->label}:</strong> " . $form->getValue('scf_phone') . "<br>";
    $messageBody .= "<strong>{$fields->get('scf_email')->label}:</strong> " . $form->getValue('scf_email') . "<br>";
    // Retrieve the title of the selected legal service
    $selectedLegalServiceID = $form->getValue('scf_legalservice');
    $selectedLegalService = wire('pages')->get($selectedLegalServiceID);
    $selectedLegalServiceTitle = $selectedLegalService ? $selectedLegalService->title : 'Not specified';
    $messageBody .= "<strong>{$fields->get('scf_legalservice')->label}:</strong> " . $selectedLegalServiceTitle . "<br>";
    $messageBody .= "<strong>{$fields->get('scf_message')->label}:</strong> " . $form->getValue('scf_message') . "<br>";
// Redirect to the success page
    wire('session')->redirect(wire('config')->urls->root . 'forfragan-skickades/');

echo $form->render();


Link to comment
Share on other sites

There is nothing wrong with your redirect, but in your case a better place for the redirect would be only after the mail has been sent (inside the if condition):

   wire('session')->redirect(wire('config')->urls->root . 'forfragan-skickades/');

I have tested it on my site with a redirect to another page -> works without problems.

There must be another problem with your system. Sometimes ProcessWire does unconventional things and struggles even all codes are OK. Closing the browser completely to delete all sessions would help in most cases (Reset). I have struggled sometimes with those problems during development of modules, where I am changing code, got errors and afterwards ProcessWire was a little bit out of control. Reseting it by closing and opening again is sometimes the best way.

10 hours ago, Flashmaster82 said:

I think the problem was $m->from('noreply@...'); but im not sure.

I am pretty sure that this was not the problem. My guess: Either it was the system problem as described above or you had a misspelling of your receiver email address (not the from address)

  • Like 1
Link to comment
Share on other sites

Hello @Flashmaster82

The new update could be interesting for you:


On 1/6/2024 at 9:45 PM, Flashmaster82 said:

I´m facing a new problem though.. I can´t get it to redirect after sending?

This update includes a new method for redirecting after form submission in an easy way.

Use the setRedirectURL() method

$form->setRedirectURL('www.google.com'); // enter the redirect URL inside the parenthesis

This will redirect to another page/URL after successful form submission. No more need to add the redirect inside the isValid() method.

Best regards

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Version 1.2.0 ist out!

This version supports mail sending with Postmark mail sending service.

Read the full changelog.md for more information about Postmark and what has been changed.

If you have one of the Postmark modules as mentioned in the changelog installed, you will find a new configuration field inside the module configuration.


Here you can select if you want to send your mails with Postmark or not. Selecting "none" means using the default WireMail class for sending mails.

In order to work properly, you will need at least FrontendForms 2.1.57 installed (as mentiond in the changelog.md).

As always, this is Beta-status, so please take care that everything works as expected.

Happy testing! 😃


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...