Jump to content

Recommended Posts

Posted

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
Posted

I think the problem was $m->from('noreply@...'); but im not sure.. I´m facing a new problem though.. I can´t get it to redirect after sending?

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

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

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

if($form->isValid()){
    
    
    $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
    
    
    $p->save();
    
    
    $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>";
    
    $m->bodyHTML($messageBody);
    $m->send();
    
// Redirect to the success page
    wire('session')->redirect(wire('config')->urls->root . 'forfragan-skickades/');
}

echo $form->render();
?>

 

Posted

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):

if($m->send()){
   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
Posted

Hello @Flashmaster82

The new update could be interesting for you:

https://processwire.com/talk/topic/26015-frontendforms-a-module-for-creating-and-validating-forms-on-the-frontend/?do=findComment&comment=238354

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
  • 2 weeks later...
Posted

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.

postmark.thumb.jpg.cf86da38e2a3edd27fb268273662bf1f.jpg

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! ?

Jürgen

  • 6 months later...
Posted

Version 1.3.6 comes with 2 new features:

  • New configuration field to limit the filesize of uploaded files globally
  • Save mails as pages too (user request by @Flashmaster82 in the forum here

save-action.jpg.e4ed656f8820fb60d9c53e49eef85def.jpg

You can read more about the new features here in the changelogs.

Please test it carefully before using it on live sites and have fun! 🙂

  • 5 months later...
Posted

When I entered an email in the config I got this:

Aw shucks… Fatal Error: Uncaught TypeError: explode(): Argument #2 ($string) must be of type string, null given in site/modules/FrontendContact/FrontendContact.module:345

#0 site/modules/FrontendContact/FrontendContact.module (345): explode('_', NULL)
#1 wire/core/Wire.php (416): FrontendContact->checkForFrontendContactEmailField(Object(HookEvent))
#2 wire/core/WireHooks.php (1102): Wire->_callMethod('checkForFronten...', Array)
#3 wire/core/Wire.php (484): WireHooks->runHooks(Object(InputfieldEmail), 'processInput', Array)
#4 wire/modules/Inputfield/InputfieldForm.module (385): Wire->__call('processInput', Array)
#5 wire/modules/Inputfield/InputfieldForm.module (244): InputfieldForm->processInputShowIf(Object(WireInputData), Array)
#6 wire/core/Wire.php (416): InputfieldForm->___processInput(Object(WireInputData))
#7 wire/core/WireHooks.php (998): Wire->_callMethod('___processInput', Array)
#8 wire/core/Wire.php (484): WireHooks->runHooks(Object(InputfieldForm), 'processInput', Array)
#9 wire/modules/Process/ProcessModule/ProcessModule.module (1809): Wire->__call('processInput', Array)
#10 wire/modules/Process/ProcessModule/ProcessModule.module (1435): ProcessModule->renderEdit('FrontendContact', Array)
#11 wire/core/Wire.php (413): ProcessModule->___executeEdit()
#12 wire/core/WireHooks.php (998): Wire->_callMethod('___executeEdit', Array)
#13 wire/core/Wire.php (484): WireHooks->runHooks(Object(ProcessModule), 'executeEdit', Array)
#14 wire/core/ProcessController.php (361): Wire->__call('executeEdit', Array)
#15 wire/core/Wire.php (413): ProcessController->___execute()
#16 wire/core/WireHooks.php (998): Wire->_callMethod('___execute', Array)
#17 wire/core/Wire.php (484): WireHooks->runHooks(Object(ProcessController), 'execute', Array)
#18 wire/core/admin.php (174): Wire->__call('execute', Array)
#19 wire/modules/AdminTheme/AdminThemeDefault/controller.php (13): require('/Users/claus/Gi...')
#20 site/templates/admin.php (15): require('/Users/claus/Gi...')
#21 wire/core/TemplateFile.php (328): require('/Users/claus/Gi...')
#22 wire/core/Wire.php (413): TemplateFile->___render()
#23 wire/core/WireHooks.php (998): Wire->_callMethod('___render', Array)
#24 wire/core/Wire.php (484): WireHooks->runHooks(Object(TemplateFile), 'render', Array)
#25 wire/modules/PageRender.module (581): Wire->__call('render', Array)
#26 wire/core/Wire.php (416): PageRender->___renderPage(Object(HookEvent))
#27 wire/core/WireHooks.php (998): Wire->_callMethod('___renderPage', Array)
#28 wire/core/Wire.php (484): WireHooks->runHooks(Object(PageRender), 'renderPage', Array)
#29 wire/core/WireHooks.php (1099): Wire->__call('renderPage', Array)
#30 wire/core/Wire.php (484): WireHooks->runHooks(Object(Page), 'render', Array)
#31 wire/modules/Process/ProcessPageView.module (193): Wire->__call('render', Array)
#32 wire/modules/Process/ProcessPageView.module (114): ProcessPageView->renderPage(Object(Page), Object(PagesRequest))
#33 wire/core/Wire.php (416): ProcessPageView->___execute(true)
#34 wire/core/WireHooks.php (998): Wire->_callMethod('___execute', Array)
#35 wire/core/Wire.php (484): WireHooks->runHooks(Object(ProcessPageView), 'execute', Array)
#36 index.php (55): Wire->__call('execute', Array)
#37 {main}
thrown (line 345 of site/modules/FrontendContact/FrontendContact.module)

This error message was shown because: you are logged in as a Superuser. Error has been logged.

If I load the site, the email is show, but as the posters email which is not right. The poster/user should enter their own email and the recipient email address I enter in the config should remain hidden from the poster/user. What am I doing wrong?

  • Like 1
Posted

Hello @Claus

Thanks for reporting this issue. There was a bug in the email validation method and I have fixed it now. Please update to the latest version 1.3.12 and everything should work as expected.

Best regards Jürgen

Posted
13 hours ago, Claus said:

If I load the site, the email is show, but as the posters email which is not right. The poster/user should enter their own email and the recipient email address I enter in the config should remain hidden from the poster/user. What am I doing wrong?

If a user is logged in, than the email address will be pre-filled with the value from the user page of this user. This is the default behavior. If user is a guest, than the user has to fill out the email address manually.

But it is not possible, that the email address from the configuration will be displayed in the email field.

Please check this once more. If the problem persists after the update, you can send me screenshots of the issue via PM if you want.

Posted

Hi Jürgen! Thank you for fixing this so quickly. Indeed I was logged in while testing, and this caused the email field to be populated with the email address that happens to also be the recipient address. In the logged out state it is not populated as expected 😉

Now I can test with eg. a Gmail address (as sender address), but then I get this error message

Email is not a valid email address, because an active DNS record could not be found.

Any idea what that is about? I’m running in on a local machine using WireMailSmtp, and I can successfully send test mails from the config page of WireMailSmtp using the same email addresses.

  • Like 1
Posted

Hello @Claus

Thanks for confirming that the problem is solved now. Regarding to your new problem: This error message comes from the validator of the Valitron library which I use to validate form fields. This is an external library and not written by myself.

This validator checks if the given email domain (fe gmail.com) exists. If not it throws an error, but it does not check if the full email address exists (fe myemail@gmail.com).

I have tested it with one of my Gmail addresses locally and there was no problem, but this email address ends with "gmail.com". Do you use another Gmail domain than "gmail.com"? You can also send me the Gmail address which causes the error via PW because it is not recommended to post it here and I will test it on my site.

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...