reconstruction of the project
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\View;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
|
||||
class ContactController extends BaseController
|
||||
{
|
||||
public function __construct(private \CodeIgniter\HTTP\IncomingRequest $request)
|
||||
{
|
||||
helper('form'); // Load the form helper
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('/parent/contact');
|
||||
}
|
||||
|
||||
public function submit()
|
||||
{
|
||||
helper('form'); // Ensure the form helper is loaded
|
||||
|
||||
$validation = \Config\Services::validation();
|
||||
|
||||
// Define validation rules
|
||||
$validation->setRules([
|
||||
'name' => 'required|min_length[3]',
|
||||
'email' => 'required|valid_email',
|
||||
'subject' => 'required|min_length[3]',
|
||||
'message' => 'required|min_length[10]'
|
||||
]);
|
||||
|
||||
if (!$validation->withRequest($this->request)->run()) {
|
||||
return view('/parent/contact', [
|
||||
'validation' => $validation
|
||||
]);
|
||||
}
|
||||
|
||||
// Process form data
|
||||
$name = $this->request->getPost('name');
|
||||
$email = strtolower($this->request->getPost('email'));
|
||||
$subject = $this->request->getPost('subject');
|
||||
$message = $this->request->getPost('message');
|
||||
|
||||
// Initialize the EmailController
|
||||
$emailController = new \App\Controllers\View\EmailController();
|
||||
|
||||
// Prepare the message to send
|
||||
$formattedMessage = "
|
||||
<p><strong>From:</strong> {$name} ({$email})</p>
|
||||
<p><strong>Subject:</strong> {$subject}</p>
|
||||
<p>{$message}</p>
|
||||
";
|
||||
|
||||
// Send the email using EmailController
|
||||
if ($emailController->sendEmail('support@alrahmaisgl.org', $subject, $formattedMessage)) {
|
||||
$session = session();
|
||||
$session->setFlashdata('success', 'Thank you for contacting us! We will get back to you soon.');
|
||||
} else {
|
||||
$session = session();
|
||||
$session->setFlashdata('error', 'There was an error sending your message. Please try again later.');
|
||||
}
|
||||
|
||||
return redirect()->to('/parent/contact');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user