diff --git a/config/Migrations/20250103091420_CreateContactUsFormSubmissions.php b/config/Migrations/20250103091420_CreateContactUsFormSubmissions.php index e9bec0f..1a90eb7 100644 --- a/config/Migrations/20250103091420_CreateContactUsFormSubmissions.php +++ b/config/Migrations/20250103091420_CreateContactUsFormSubmissions.php @@ -28,17 +28,22 @@ class CreateContactUsFormSubmissions extends AbstractMigration { 'limit' => 45, 'null' => true, ]); - $table->addColumn('name', 'string', [ + $table->addColumn('first_name', 'string', [ 'default' => null, 'limit' => 255, - 'null' => false, + 'null' => true, + ]); + $table->addColumn('last_name', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true, ]); $table->addColumn('email', 'string', [ 'default' => null, 'limit' => 255, 'null' => true, ]); - $table->addColumn('subject', 'string', [ + $table->addColumn('contact_subject', 'string', [ 'default' => null, 'limit' => 255, 'null' => true, diff --git a/config/Migrations/20260123091420_AlterContactUsFormSubmissionsKeywords.php b/config/Migrations/20260123091420_AlterContactUsFormSubmissionsKeywords.php deleted file mode 100644 index 37916bd..0000000 --- a/config/Migrations/20260123091420_AlterContactUsFormSubmissionsKeywords.php +++ /dev/null @@ -1,50 +0,0 @@ -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(); - } - -} diff --git a/src/Controller/Component/ContactUsComponent.php b/src/Controller/Component/ContactUsComponent.php index 2c9cea5..ba5b5dc 100644 --- a/src/Controller/Component/ContactUsComponent.php +++ b/src/Controller/Component/ContactUsComponent.php @@ -90,7 +90,6 @@ class ContactUsComponent extends Component { 'contactUsFormSubmission' => $contactUsFormSubmission, ], $this->getController()); $result = $event->getResult(); - Log::debug(print_r('$result', true)); Log::debug(print_r($result, true)); if ($result instanceof EntityInterface) { @@ -104,15 +103,13 @@ class ContactUsComponent extends Component { if ($contactUsFormSubmissionSaved) { return $this->_afterFormSaved($contactUsFormSubmissionSaved); } - // @TODO contact us form submission failed - handle here } if ($event->isStopped()) { return $this->getController()->redirect($event->getResult()); } - - if (!$this->getController()->getRequest()->is('post')) { + if (!$postData) { return; } diff --git a/src/Mailer/ContactUsFormSubmissionsMailer.php b/src/Mailer/ContactUsFormSubmissionsMailer.php index f80d85e..4ff4f35 100644 --- a/src/Mailer/ContactUsFormSubmissionsMailer.php +++ b/src/Mailer/ContactUsFormSubmissionsMailer.php @@ -45,7 +45,7 @@ class ContactUsFormSubmissionsMailer extends Mailer { */ protected function backend(ContactUsFormSubmission $contactUsFormSubmission, array $options = []) { $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'); $cc = Configure::read('ContactUs.email.backend.cc', []); @@ -62,7 +62,7 @@ class ContactUsFormSubmissionsMailer extends Mailer { if ($cc) { $cc = !is_array($cc) ? [$cc] : $cc; - $this->setCc($to); + $this->setCc($cc); } if ($bcc) { $bcc = !is_array($bcc) ? [$bcc] : $bcc; diff --git a/src/Model/Entity/ContactUsFormSubmission.php b/src/Model/Entity/ContactUsFormSubmission.php index 1688aea..0260521 100644 --- a/src/Model/Entity/ContactUsFormSubmission.php +++ b/src/Model/Entity/ContactUsFormSubmission.php @@ -11,7 +11,8 @@ use Cake\ORM\Entity; * @property string $id * @property \Cake\I18n\DateTime $submitted_at * @property string $client_ip - * @property string $name + * @property string|null $first_name + * @property string|null $last_name * @property string|null $email * @property string|null $contact_subject * @property string $message @@ -32,7 +33,8 @@ class ContactUsFormSubmission extends Entity { protected array $_accessible = [ 'submitted_at' => true, 'client_ip' => true, - 'name' => true, + 'first_name' => true, + 'last_name' => true, 'email' => true, 'contact_subject' => true, 'message' => true, @@ -40,4 +42,11 @@ class ContactUsFormSubmission extends Entity { 'backend_email_sent' => true, ]; + /** + * @return string + */ + protected function _getFullName(): string { + return $this->get('first_name') . ' ' . $this->get('last_name'); + } + } diff --git a/src/Model/Table/ContactUsFormSubmissionsTable.php b/src/Model/Table/ContactUsFormSubmissionsTable.php index d738ce1..6b930c5 100644 --- a/src/Model/Table/ContactUsFormSubmissionsTable.php +++ b/src/Model/Table/ContactUsFormSubmissionsTable.php @@ -46,7 +46,7 @@ class ContactUsFormSubmissionsTable extends Table { parent::initialize($config); $this->setTable('contact_us_form_submissions'); - $this->setDisplayField('name'); + $this->setDisplayField('email'); $this->setPrimaryKey('id'); } @@ -69,10 +69,15 @@ class ContactUsFormSubmissionsTable extends Table { ->allowEmptyString('client_ip'); $validator - ->scalar('name') - ->maxLength('name', 255) - ->requirePresence('name', 'create') - ->notEmptyString('name'); + ->scalar('first_name') + ->maxLength('first_name', 255) + ->requirePresence('first_name', 'create') + ->notEmptyString('first_name'); + + $validator + ->scalar('last_name') + ->maxLength('last_name', 255) + ->allowEmptyString('last_name'); // email $validator->email('email'); diff --git a/templates/Admin/ContactUsFormSubmissions/edit.php b/templates/Admin/ContactUsFormSubmissions/edit.php index f288a22..c289c1c 100644 --- a/templates/Admin/ContactUsFormSubmissions/edit.php +++ b/templates/Admin/ContactUsFormSubmissions/edit.php @@ -24,9 +24,10 @@ Form->control('submitted_at'); 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('subject'); + echo $this->Form->control('contact_subject'); echo $this->Form->control('message'); echo $this->Form->control('confirm_email_sent', ['empty' => true]); echo $this->Form->control('backend_email_sent', ['empty' => true]); diff --git a/templates/Admin/ContactUsFormSubmissions/index.php b/templates/Admin/ContactUsFormSubmissions/index.php index 3606b9a..23a49ad 100644 --- a/templates/Admin/ContactUsFormSubmissions/index.php +++ b/templates/Admin/ContactUsFormSubmissions/index.php @@ -13,9 +13,9 @@
| = __('Id') ?> | @@ -27,7 +27,7 @@||
|---|---|---|
| = __('Name') ?> | -= h($contactUsFormSubmission->name) ?> | += h($contactUsFormSubmission->full_name) ?> |
| = __('Email') ?> | @@ -35,7 +35,7 @@||
| = __('Subject') ?> | -= h($contactUsFormSubmission->subject) ?> | += h($contactUsFormSubmission->contact_subject) ?> |
| = __('Submitted At') ?> | diff --git a/templates/ContactUsFormSubmissions/add.php b/templates/ContactUsFormSubmissions/add.php index d633cee..17e8219 100644 --- a/templates/ContactUsFormSubmissions/add.php +++ b/templates/ContactUsFormSubmissions/add.php @@ -5,10 +5,6 @@ */ ?>