first/last name instead ofj ust name, fix og migration instead of updating in second file sqlite issue

This commit is contained in:
2026-01-26 23:31:29 -08:00
parent ea1cb8cd29
commit 348665deb8
15 changed files with 74 additions and 94 deletions

View File

@@ -28,17 +28,22 @@ class CreateContactUsFormSubmissions extends AbstractMigration {
'limit' => 45, 'limit' => 45,
'null' => true, 'null' => true,
]); ]);
$table->addColumn('name', 'string', [ $table->addColumn('first_name', 'string', [
'default' => null, 'default' => null,
'limit' => 255, 'limit' => 255,
'null' => false, 'null' => true,
]);
$table->addColumn('last_name', 'string', [
'default' => null,
'limit' => 255,
'null' => true,
]); ]);
$table->addColumn('email', 'string', [ $table->addColumn('email', 'string', [
'default' => null, 'default' => null,
'limit' => 255, 'limit' => 255,
'null' => true, 'null' => true,
]); ]);
$table->addColumn('subject', 'string', [ $table->addColumn('contact_subject', 'string', [
'default' => null, 'default' => null,
'limit' => 255, 'limit' => 255,
'null' => true, 'null' => true,

View File

@@ -1,50 +0,0 @@
<?php
declare(strict_types=1);
use Migrations\AbstractMigration;
class AlterContactUsFormSubmissionsKeywords extends AbstractMigration {
/**
* up Method.
*
* More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void
*/
public function up(): void {
$table = $this->table('contact_us_form_submissions');
if ($table->hasColumn('subject')) {
$table->renameColumn('subject', 'contact_subject');
}
if ($table->hasColumn('name')) {
$table->renameColumn('name', 'first_name');
}
$table->addColumn('last_name', 'string', [
'limit' => 255,
'default' => null,
'null' => true,
]);
$table->update();
}
/**
* down Method.
*
* More information on this method is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
* @return void
*/
public function down(): void {
$table = $this->table('contact_us_form_submissions');
if ($table->hasColumn('contact_subject')) {
$table->renameColumn('contact_subject', 'subject');
}
if ($table->hasColumn('fist_name')) {
$table->renameColumn('fist_name', 'name');
}
$table->removeColumn('last_name');
$table->update();
}
}

View File

@@ -90,7 +90,6 @@ class ContactUsComponent extends Component {
'contactUsFormSubmission' => $contactUsFormSubmission, 'contactUsFormSubmission' => $contactUsFormSubmission,
], $this->getController()); ], $this->getController());
$result = $event->getResult(); $result = $event->getResult();
Log::debug(print_r('$result', true)); Log::debug(print_r('$result', true));
Log::debug(print_r($result, true)); Log::debug(print_r($result, true));
if ($result instanceof EntityInterface) { if ($result instanceof EntityInterface) {
@@ -104,15 +103,13 @@ class ContactUsComponent extends Component {
if ($contactUsFormSubmissionSaved) { if ($contactUsFormSubmissionSaved) {
return $this->_afterFormSaved($contactUsFormSubmissionSaved); return $this->_afterFormSaved($contactUsFormSubmissionSaved);
} }
// @TODO contact us form submission failed - handle here // @TODO contact us form submission failed - handle here
} }
if ($event->isStopped()) { if ($event->isStopped()) {
return $this->getController()->redirect($event->getResult()); return $this->getController()->redirect($event->getResult());
} }
if (!$postData) {
if (!$this->getController()->getRequest()->is('post')) {
return; return;
} }

View File

@@ -45,7 +45,7 @@ class ContactUsFormSubmissionsMailer extends Mailer {
*/ */
protected function backend(ContactUsFormSubmission $contactUsFormSubmission, array $options = []) { protected function backend(ContactUsFormSubmission $contactUsFormSubmission, array $options = []) {
$subject = __d('cake_contact_us', 'Contact Us Form Submitted'); $subject = __d('cake_contact_us', 'Contact Us Form Submitted');
$name = isset($contactUsFormSubmission->name) ? ' by ' . $contactUsFormSubmission->name : ''; $name = isset($contactUsFormSubmission->full_name) ? ' by ' . $contactUsFormSubmission->full_name : '';
$to = Configure::readOrFail('ContactUs.email.backend.to'); $to = Configure::readOrFail('ContactUs.email.backend.to');
$cc = Configure::read('ContactUs.email.backend.cc', []); $cc = Configure::read('ContactUs.email.backend.cc', []);
@@ -62,7 +62,7 @@ class ContactUsFormSubmissionsMailer extends Mailer {
if ($cc) { if ($cc) {
$cc = !is_array($cc) ? [$cc] : $cc; $cc = !is_array($cc) ? [$cc] : $cc;
$this->setCc($to); $this->setCc($cc);
} }
if ($bcc) { if ($bcc) {
$bcc = !is_array($bcc) ? [$bcc] : $bcc; $bcc = !is_array($bcc) ? [$bcc] : $bcc;

View File

@@ -11,7 +11,8 @@ use Cake\ORM\Entity;
* @property string $id * @property string $id
* @property \Cake\I18n\DateTime $submitted_at * @property \Cake\I18n\DateTime $submitted_at
* @property string $client_ip * @property string $client_ip
* @property string $name * @property string|null $first_name
* @property string|null $last_name
* @property string|null $email * @property string|null $email
* @property string|null $contact_subject * @property string|null $contact_subject
* @property string $message * @property string $message
@@ -32,7 +33,8 @@ class ContactUsFormSubmission extends Entity {
protected array $_accessible = [ protected array $_accessible = [
'submitted_at' => true, 'submitted_at' => true,
'client_ip' => true, 'client_ip' => true,
'name' => true, 'first_name' => true,
'last_name' => true,
'email' => true, 'email' => true,
'contact_subject' => true, 'contact_subject' => true,
'message' => true, 'message' => true,
@@ -40,4 +42,11 @@ class ContactUsFormSubmission extends Entity {
'backend_email_sent' => true, 'backend_email_sent' => true,
]; ];
/**
* @return string
*/
protected function _getFullName(): string {
return $this->get('first_name') . ' ' . $this->get('last_name');
}
} }

View File

@@ -46,7 +46,7 @@ class ContactUsFormSubmissionsTable extends Table {
parent::initialize($config); parent::initialize($config);
$this->setTable('contact_us_form_submissions'); $this->setTable('contact_us_form_submissions');
$this->setDisplayField('name'); $this->setDisplayField('email');
$this->setPrimaryKey('id'); $this->setPrimaryKey('id');
} }
@@ -69,10 +69,15 @@ class ContactUsFormSubmissionsTable extends Table {
->allowEmptyString('client_ip'); ->allowEmptyString('client_ip');
$validator $validator
->scalar('name') ->scalar('first_name')
->maxLength('name', 255) ->maxLength('first_name', 255)
->requirePresence('name', 'create') ->requirePresence('first_name', 'create')
->notEmptyString('name'); ->notEmptyString('first_name');
$validator
->scalar('last_name')
->maxLength('last_name', 255)
->allowEmptyString('last_name');
// email // email
$validator->email('email'); $validator->email('email');

View File

@@ -24,9 +24,10 @@
<?php <?php
echo $this->Form->control('submitted_at'); echo $this->Form->control('submitted_at');
echo $this->Form->control('client_ip'); echo $this->Form->control('client_ip');
echo $this->Form->control('name'); echo $this->Form->control('first_name');
echo $this->Form->control('last_name');
echo $this->Form->control('email'); echo $this->Form->control('email');
echo $this->Form->control('subject'); echo $this->Form->control('contact_subject');
echo $this->Form->control('message'); echo $this->Form->control('message');
echo $this->Form->control('confirm_email_sent', ['empty' => true]); echo $this->Form->control('confirm_email_sent', ['empty' => true]);
echo $this->Form->control('backend_email_sent', ['empty' => true]); echo $this->Form->control('backend_email_sent', ['empty' => true]);

View File

@@ -13,9 +13,9 @@
<th><?= $this->Paginator->sort('id') ?></th> <th><?= $this->Paginator->sort('id') ?></th>
<th><?= $this->Paginator->sort('submitted_at') ?></th> <th><?= $this->Paginator->sort('submitted_at') ?></th>
<th><?= $this->Paginator->sort('client_ip') ?></th> <th><?= $this->Paginator->sort('client_ip') ?></th>
<th><?= $this->Paginator->sort('name') ?></th> <th><?= $this->Paginator->sort('first_name') . ' ' . $this->Paginator->sort('last_name'); ?></th>
<th><?= $this->Paginator->sort('email') ?></th> <th><?= $this->Paginator->sort('email') ?></th>
<th><?= $this->Paginator->sort('subject') ?></th> <th><?= $this->Paginator->sort('contact_subject') ?></th>
<th><?= $this->Paginator->sort('confirm_email_sent') ?></th> <th><?= $this->Paginator->sort('confirm_email_sent') ?></th>
<th><?= $this->Paginator->sort('backend_email_sent') ?></th> <th><?= $this->Paginator->sort('backend_email_sent') ?></th>
<th class="actions"><?= __('Actions') ?></th> <th class="actions"><?= __('Actions') ?></th>
@@ -27,9 +27,9 @@
<td><?= h($contactUsFormSubmission->id) ?></td> <td><?= h($contactUsFormSubmission->id) ?></td>
<td><?= h($contactUsFormSubmission->submitted_at) ?></td> <td><?= h($contactUsFormSubmission->submitted_at) ?></td>
<td><?= h($contactUsFormSubmission->client_ip) ?></td> <td><?= h($contactUsFormSubmission->client_ip) ?></td>
<td><?= h($contactUsFormSubmission->name) ?></td> <td><?= h($contactUsFormSubmission->full_name) ?></td>
<td><?= h($contactUsFormSubmission->email) ?></td> <td><?= h($contactUsFormSubmission->email) ?></td>
<td><?= h($contactUsFormSubmission->subject) ?></td> <td><?= h($contactUsFormSubmission->contact_subject) ?></td>
<td><?= h($contactUsFormSubmission->confirm_email_sent) ?></td> <td><?= h($contactUsFormSubmission->confirm_email_sent) ?></td>
<td><?= h($contactUsFormSubmission->backend_email_sent) ?></td> <td><?= h($contactUsFormSubmission->backend_email_sent) ?></td>
<td class="actions"> <td class="actions">

View File

@@ -15,7 +15,7 @@
</aside> </aside>
<div class="column column-80"> <div class="column column-80">
<div class="contactUsFormSubmissions view content"> <div class="contactUsFormSubmissions view content">
<h3><?= h($contactUsFormSubmission->name) ?></h3> <h3><?= h($contactUsFormSubmission->email) ?></h3>
<table> <table>
<tr> <tr>
<th><?= __('Id') ?></th> <th><?= __('Id') ?></th>
@@ -27,7 +27,7 @@
</tr> </tr>
<tr> <tr>
<th><?= __('Name') ?></th> <th><?= __('Name') ?></th>
<td><?= h($contactUsFormSubmission->name) ?></td> <td><?= h($contactUsFormSubmission->full_name) ?></td>
</tr> </tr>
<tr> <tr>
<th><?= __('Email') ?></th> <th><?= __('Email') ?></th>
@@ -35,7 +35,7 @@
</tr> </tr>
<tr> <tr>
<th><?= __('Subject') ?></th> <th><?= __('Subject') ?></th>
<td><?= h($contactUsFormSubmission->subject) ?></td> <td><?= h($contactUsFormSubmission->contact_subject) ?></td>
</tr> </tr>
<tr> <tr>
<th><?= __('Submitted At') ?></th> <th><?= __('Submitted At') ?></th>

View File

@@ -5,10 +5,6 @@
*/ */
?> ?>
<div class="row"> <div class="row">
<aside class="column">
<div class="side-nav">
</div>
</aside>
<div class="column column-80"> <div class="column column-80">
<div class="contactUsFormSubmissions form content"> <div class="contactUsFormSubmissions form content">
<?= $this->Form->create($contactUsFormSubmission) ?> <?= $this->Form->create($contactUsFormSubmission) ?>

View File

@@ -7,10 +7,10 @@
$fields = \Cake\Core\Configure::readOrFail('ContactUs.fields'); $fields = \Cake\Core\Configure::readOrFail('ContactUs.fields');
?> ?>
<?php <?php
echo $this->Form->control('name'); echo $this->Form->control('first_name');
echo $this->Form->control('last_name');
echo isset($fields['email']) && $fields['email'] ? $this->Form->control('email', ['required' => true]) : ''; echo isset($fields['email']) && $fields['email'] ? $this->Form->control('email', ['required' => true]) : '';
echo isset($fields['subject']) && $fields['subject'] ? $this->Form->control('subject', ['required' => true]) : ''; echo isset($fields['subject']) && $fields['subject'] ? $this->Form->control('subject', ['required' => true]) : '';
echo $this->Form->control('message'); echo $this->Form->control('message');
echo isset($fields['captcha']) && $fields['captcha'] ? $this->Captcha->render(['placeholder' => __('Please solve the riddle')]) : ''; echo isset($fields['captcha']) && $fields['captcha'] ? $this->Captcha->render(['placeholder' => __('Please solve the riddle')]) : '';
?> ?>

View File

@@ -11,7 +11,7 @@ use Cake\Core\Configure;
<?= __d('cake_contact_us', "A contact us form submission was received at {0}", $contactUsFormSubmission->submitted_at) ?>, <?= __d('cake_contact_us', "A contact us form submission was received at {0}", $contactUsFormSubmission->submitted_at) ?>,
</p> </p>
<p> <p>
<?= h($contactUsFormSubmission->name); ?> <?= h($contactUsFormSubmission->full_name); ?>
</p> </p>
<?php if (Configure::read('ContactUs.fields.email', false) && isset($contactUsFormSubmission->email)) : ?> <?php if (Configure::read('ContactUs.fields.email', false) && isset($contactUsFormSubmission->email)) : ?>
<p> <p>
@@ -20,10 +20,10 @@ use Cake\Core\Configure;
</p> </p>
<?php endif; ?> <?php endif; ?>
<?php if (Configure::read('ContactUs.fields.subject', false) && isset($contactUsFormSubmission->subject)) : ?> <?php if (Configure::read('ContactUs.fields.subject', false) && isset($contactUsFormSubmission->contact_subject)) : ?>
<p> <p>
<strong><?= __d('cake_contact_us', 'Subject: ') ?></strong> <strong><?= __d('cake_contact_us', 'Subject: ') ?></strong>
<span><?= h($contactUsFormSubmission->subject); ?></span> <span><?= h($contactUsFormSubmission->contact_subject); ?></span>
</p> </p>
<?php endif; ?> <?php endif; ?>
<p> <p>

View File

@@ -3,7 +3,9 @@ declare(strict_types=1);
namespace CakeContactUs\Test\Fixture; namespace CakeContactUs\Test\Fixture;
use Cake\I18n\FrozenTime;
use Cake\TestSuite\Fixture\TestFixture; use Cake\TestSuite\Fixture\TestFixture;
use Cake\Utility\Text;
/** /**
* ContactUsFormSubmissionsFixture * ContactUsFormSubmissionsFixture
@@ -18,7 +20,21 @@ class ContactUsFormSubmissionsFixture extends TestFixture {
* @return void * @return void
*/ */
public function init(): void { public function init(): void {
$this->records = []; $this->records = [
[
'id' => Text::uuid(),
'submitted_at' => new FrozenTime(),
'client_ip' => 'cli',
'first_name' => 'test',
'last_name' => 'test',
'email' => 'test@test.com',
'contact_subject' => 'subject',
'message' => 'what are your business hours?',
'confirm_email_sent' => true,
'backend_email_sent' => true,
],
];
parent::init(); parent::init();
} }

View File

@@ -72,13 +72,14 @@ class ContactUsComponentTest extends TestCase {
* @return void * @return void
*/ */
public function testProcessContactUsFormSaved() { public function testProcessContactUsFormSaved() {
$numSubmissionsBefore = $this->fetchTable('CakeContactUs/ContactUsFormSubmissions')->find()->count(); $numSubmissionsBefore = $this->fetchTable('CakeContactUs.ContactUsFormSubmissions')->find()->count();
$result = $this->component->processContactUsForm($this->component->newContactUsForm(), [ $result = $this->component->processContactUsForm($this->component->newContactUsForm(), [
'name' => 'Jane Doe', 'first_name' => 'Jane Doe',
'email' => 'test@example.com', 'email' => 'test@example.com',
'message' => 'contact us message',
]); ]);
$this->assertNotInstanceOf(ContactUsFormSubmission::class, $result); $this->assertNotInstanceOf(ContactUsFormSubmission::class, $result);
$numSubmissionsAfter = $this->fetchTable('CakeContactUs/ContactUsFormSubmissions')->find()->count(); $numSubmissionsAfter = $this->fetchTable('CakeContactUs.ContactUsFormSubmissions')->find()->count();
$this->assertEquals($numSubmissionsBefore + 1, $numSubmissionsAfter); $this->assertEquals($numSubmissionsBefore + 1, $numSubmissionsAfter);
} }

View File

@@ -105,7 +105,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase {
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'name' => 'valid name', 'first_name' => 'valid name',
'email' => 'valid_email@test.com', 'email' => 'valid_email@test.com',
'message' => 'valid message goes here', 'message' => 'valid message goes here',
]; ];
@@ -156,7 +156,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase {
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'name' => 'valid name', 'first_name' => 'valid name',
'email' => 'valid_email@test.com', 'email' => 'valid_email@test.com',
'message' => 'valid message goes here', 'message' => 'valid message goes here',
]; ];
@@ -203,7 +203,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase {
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'name' => 'valid name', 'first_name' => 'valid name',
'email' => 'valid_email@test.com', 'email' => 'valid_email@test.com',
'message' => 'valid message goes here', 'message' => 'valid message goes here',
]; ];
@@ -251,7 +251,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase {
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'name' => 'valid name', 'first_name' => 'valid name',
'email' => 'valid_email@test.com', 'email' => 'valid_email@test.com',
'message' => 'valid message goes here', 'message' => 'valid message goes here',
]; ];
@@ -290,7 +290,7 @@ class ContactUsFormSubmissionsControllerTest extends TestCase {
'action' => 'add', 'action' => 'add',
]; ];
$data = [ $data = [
'name' => 'valid name', 'first_name' => 'valid name',
'email' => 'not_valid_email', 'email' => 'not_valid_email',
'message' => 'this is a valid message ', 'message' => 'this is a valid message ',
]; ];