Zitat von
Spooky
Hab ich mal eingetragen. Magst du mal drüber lesen?
PHP-Code:
<?php
// src/EventListener/PrepareFormDataListener.php
namespace App\EventListener;
use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\Form;
use Contao\CoreBundle\Slug\Slug;
/**
* @Hook("prepareFormData")
*/
class PrepareFormDataListener
{
private $slug;
public function __construct(Slug $slug)
{
$this->slug = $slug;
}
public function __invoke(array &$submittedData, array $labels, array $fields, Form $form): void
{
// form restriction
if ($form->id == "3") {
// see BE info
$submittedData['pid'] = 5;
$submittedData['author'] = 1;
$submittedData['published'] = 1;
$tmpTitle = "Reservierung - " . $submittedData['title'];
$submittedData['title'] = $tmpTitle;
$submittedData['alias'] = $this->slug->generate($tmpTitle, ['validChars' => 'a-z0-9', 'locale' => 'de', 'delimiter' => '-']);
// mandatory field
$submittedData['startTime'] = strtotime($submittedData['startDate']);
// optional field
if (!empty(trim($submittedData['endDate']))) {
$submittedData['endTime'] = strtotime($submittedData['endDate']);
} else {
$submittedData['endTime'] = null;
$submittedData['endDate'] = null;
}
$submittedData['location'] = "WSG";
$submittedData['description'] = "Reservierung Vereins-Boot";
}
}
}
?>