Skip to content

Commit

Permalink
Merge pull request #117 from falmesino/bugfix/no-ref/unable-to-save-d…
Browse files Browse the repository at this point in the history
…ate-into-db

fix: unable to save date into database
  • Loading branch information
bobdenotter authored Feb 17, 2023
2 parents 41d5e37 + f6bb007 commit ac18132
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/EventSubscriber/DbTablePersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Bolt\BoltForms\EventSubscriber;

use Bolt\BoltForms\Event\PostSubmitEvent;
use Carbon\Carbon;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Query\QueryBuilder;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -67,12 +68,19 @@ private function parseForm(Form $form, PostSubmitEvent $event, Collection $confi
private function saveToTable(string $table, array $fields): void
{
$columns = [];
$parameters = [];

foreach (array_keys($fields) as $name) {
$columns[$name] = '?';
}

$parameters = array_values($fields);
foreach(array_values($fields) as $value) {
if ($value instanceof \DateTimeInterface) {
$parameters[] = Carbon::instance($value);
} else {
$parameters[] = $value;
}
}

$this->query
->insert($table)
Expand Down

0 comments on commit ac18132

Please sign in to comment.