thx @szabesz
Hi @Andy thx for your kind words!
well... I like to do thinks in code rather than clicking around a GUI, because then I have all in GIT and can automatically deploy it to production. In addition to that I love how you can write form code once and get frontend and backend validation of your forms automatically. The next point is that I don't like the embed methods via Iframe and I never got used to the other output method - how is it called? Direct output?
Another point is that I try to avoid hook hell as much as possible. Hooks are great, but I started to adopt concepts where things that belong together are in the same file or folder. That's why every form that I create for RockForms is one single PHP file, that defines all the necessary pieces (fields, after submit action like sending an email, markup for the frontend, error messages...).
<?php namespace ProcessWire;
/** @var RockForms $rockforms */
$form = $rockforms->form('newsletter', [
'token' => false, // disable csrf for use with procache!
]);
$form->setMarkup("field(email)", "<div class='sr-only'>{label}</div>{control}{errors}");
$form->getElementPrototype()->addClass('mb-12');
$form->addText("email", "E-Mail Adresse")
->setHtmlAttribute("class", "text-gray-dark w-full focus:border-violet focus:ring-violet")
->setHtmlAttribute("placeholder", "Ihre E-Mail Adresse")
->isRequired();
$form->addMarkup("<button type='submit' class='btn btn-sm btn-pink !px-12 mt-6'>Newsletter abonnieren</button>");
if($form->isSuccess()) {
$values = $form->getValues();
if($form->once()) {
/** @var RockMails $mails */
$mails = $this->wire('modules')->get('RockMails');
$mails->mail('newsletter')
->to('office@example.com')
->subject("New Newsletter Subscription")
->bodyHTML($form->dataTable())
->send();
$this->log('sent mail');
}
$form->success('<span style="color:black;">Thank you for your subscription</span>');
}
return $form;
This is an example for an easy newsletter subscription form.
For me it is also better to code my own module because then I have a lot more freedom and can add extensions and new features while working on any project that uses the module. For example the $form->dataTable() is something I need very often (send form data via mail or show form data in the backend).
I guess I'll release this as commercial module soon - if anybody reads this and is interested in a closed alpha write me a PM ?