Ver código fonte

Updated forms

Samson Mutunga 2 anos atrás
pai
commit
b1e3acab01

+ 52 - 0
app/Http/Controllers/AppController.php

@@ -2,10 +2,17 @@
 
 namespace App\Http\Controllers;
 
+use App\Http\Traits\StringGeneratorTrait;
+use Ramsey\Uuid\Uuid;
+
 use Illuminate\Http\Request;
+use App\Models\FindAClinicRequest;
+use App\Models\ContactMessage;
 
 class AppController extends Controller
 {
+  use StringGeneratorTrait;
+
     public function index() {
       return view('app.index');
     }
@@ -33,4 +40,49 @@ class AppController extends Controller
     public function findAClinic() {
       return view('app.find-a-clinic');
     }
+    public function submitFindAClinic(Request $request) {
+      $request->validate([
+        'name_first' => 'required|string',
+        'name_last' => 'required|string',
+        'email' => 'required|email',
+        'phone' => 'required|string',
+        'zip' => 'required|string'
+      ]);
+      
+      $record = new FindAClinicRequest;
+      $record->iid = $this->makeIID();
+      $record->uid = Uuid::uuid6();
+      $record->name_first = $request->get('name_first');
+      $record->name_last = $request->get('name_last');
+      $record->email = $request->get('email');
+      $record->phone = $request->get('phone');
+      $record->zip = $request->get('zip');
+
+      $record->save();
+      return redirect()->back()->with('success', 'Your request has been submitted!');
+    }
+
+    public function submitContact(Request $request) {
+      $request->validate([
+        'name_first' => 'required|string',
+        'name_last' => 'required|string',
+        'email' => 'required|email',
+        'phone' => 'string',
+        'subject' => 'string',
+        'message' => 'required|string'
+      ]);
+      
+      $record = new ContactMessage;
+      $record->iid = $this->makeIID();
+      $record->uid = Uuid::uuid6();
+      $record->name_first = $request->get('name_first');
+      $record->name_last = $request->get('name_last');
+      $record->email = $request->get('email');
+      $record->phone = $request->get('phone');
+      $record->subject = $request->get('subject');
+      $record->message = $request->get('message');
+
+      $record->save();
+      return redirect()->back()->with('success', 'Your request has been submitted!');
+    }
 }

+ 60 - 0
app/Http/Traits/KeysIdsTrait.php

@@ -0,0 +1,60 @@
+<?php
+
+
+namespace App\Http\Traits;
+
+
+use App\Models\AppSession;
+
+trait KeysIdsTrait
+{
+	public function getId ($object)
+	{
+		if( !$object) {
+			return false;
+		}
+		if( !$object->id) {
+			return false;
+		}
+		return $object->id;
+	}
+	
+	public function getIid ($object)
+	{
+		if( !$object) {
+			return false;
+		}
+		if( !$object->iid) {
+			return false;
+		}
+		return $object->iid;
+	}
+	
+	public function getUid ($object)
+	{
+		if( !$object) {
+			return false;
+		}
+		if( !$object->uid) {
+			return false;
+		}
+		return $object->uid;
+	}
+	
+	public function saveForeignKey ($object)
+	{
+		return $object->id;
+	}
+	
+	public function getCurrentSessionId ()
+	{
+		return request()->cookie("credo_session_key");
+	}
+	
+	public function getCurrentAgentId ()
+	{
+		$sessionKey = $this->getCurrentSessionId();
+		$appSession = AppSession::where("session_key", $sessionKey)->first();
+		return $appSession->agent->uid;
+	}
+}

+ 36 - 0
app/Http/Traits/StringGeneratorTrait.php

@@ -0,0 +1,36 @@
+<?php
+
+
+namespace App\Http\Traits;
+
+
+trait StringGeneratorTrait
+{
+
+
+    public function makeIID ()
+    {
+        return $this->generateRandomAlphabeticString(3) . $this->generateRandomNumericString(3);
+    }
+
+    public function generateRandomAlphabeticString($length = 6) {
+        $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+        $charactersLength = strlen($characters);
+        $randomString = '';
+        for ($i = 0; $i < $length; $i++) {
+            $randomString .= $characters[rand(0, $charactersLength - 1)];
+        }
+        return $randomString;
+    }
+
+    public function generateRandomNumericString($length = 6) {
+        $characters = '1234567890';
+        $charactersLength = strlen($characters);
+        $randomString = '';
+        for ($i = 0; $i < $length; $i++) {
+            $randomString .= $characters[rand(0, $charactersLength - 1)];
+        }
+        return $randomString;
+    }
+
+}

+ 24 - 0
app/Models/Base/BaseModel.php

@@ -0,0 +1,24 @@
+<?php
+
+
+namespace App\Models\Base;
+
+use App\Models\RecordStatus;
+use Illuminate\Database\Eloquent\Model;
+
+class BaseModel extends Model
+{
+
+	protected $primaryKey = 'id';
+
+	public function getRouteKeyName(): string
+	{
+		return 'uid';
+	}
+
+
+	public function getTableName(): string
+	{
+		return $this->table;
+	}
+}

+ 11 - 0
app/Models/ContactMessage.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+use App\Models\Base\BaseModel;
+use Illuminate\Database\Eloquent\Model;
+
+class ContactMessage extends BaseModel
+{
+    protected $table = 'contact_message';
+}

+ 11 - 0
app/Models/FindAClinicRequest.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+use App\Models\Base\BaseModel;
+use Illuminate\Database\Eloquent\Model;
+
+class FindAClinicRequest extends BaseModel
+{
+    protected $table = 'find_a_clinic_request';
+}

+ 2 - 0
database/migrations/2014_10_12_000000_create_users_table.php

@@ -15,6 +15,8 @@ class CreateUsersTable extends Migration
     {
         Schema::create('users', function (Blueprint $table) {
             $table->id();
+            $table->string('uid')->unique();
+            $table->string('iid')->unique();
             $table->string('name');
             $table->string('email')->unique();
             $table->timestamp('email_verified_at')->nullable();

+ 38 - 0
database/migrations/2022_11_14_084640_create_find_a_clinic_request.php

@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateFindAClinicRequest extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('find_a_clinic_request', function (Blueprint $table) {
+            $table->id();
+            $table->string('uid')->unique();
+            $table->string('iid')->unique();
+            $table->string('name_first');
+            $table->string('name_last');
+            $table->string('email');
+            $table->string('phone');
+            $table->string('zip');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('find_a_clinic_request');
+    }
+}

+ 39 - 0
database/migrations/2022_11_14_092057_create_contact_message_table.php

@@ -0,0 +1,39 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateContactMessageTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('contact_message', function (Blueprint $table) {
+            $table->id();
+            $table->string('uid')->unique();
+            $table->string('iid')->unique();
+            $table->string('name_first');
+            $table->string('name_last');
+            $table->string('email')->nullable();
+            $table->string('phone')->nullable();
+            $table->string('subject')->nullable();
+            $table->text('message')->nullable();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('contact_message');
+    }
+}

+ 31 - 6
resources/views/app/contact.blade.php

@@ -15,25 +15,50 @@
     <div class="col-lg-6 bg-grey p-lg-5 p-4 mb-4" style="border-bottom:7px solid var(--pry-color);">
       <h4 class="subtitle">Get in touch with us:</h4>
       <p class="mb-4">Send us Message and we will get back to you!</p>
-      <form class="" action="" method="post">
+      <form class="" action="{{ route('submit-contact') }}" method="post">
         @csrf
         <div class="row">
           <div class="col-lg-6 form-group mb-4">
-            <input type="text" class="form-control rounded-0 py-3" name="fname" placeholder="First Name" required value="">
+            <input type="text" class="form-control rounded-0 py-3" name="name_first" placeholder="First Name" value="{{ old('name_first') }}">
+            @error('name_first')
+              <small class="text-warning">{{$message}}</small>
+            @enderror
           </div>
           <div class="col-lg-6 form-group mb-4">
-            <input type="text" class="form-control rounded-0 py-3" name="lname" placeholder="Last Name" required value="">
+            <input type="text" class="form-control rounded-0 py-3" name="name_last" placeholder="Last Name" value="{{ old('name_last') }}">
+            @error('name_last')
+              <small class="text-warning">{{$message}}</small>
+            @enderror
           </div>
         </div>
         <div class="form-group mb-4">
-          <input type="email" class="form-control rounded-0 py-3" name="email" placeholder="Email Address" required value="">
+          <input type="email" class="form-control rounded-0 py-3" name="email" placeholder="Email Address" value="{{ old('email') }}">
+          @error('email')
+              <small class="text-warning">{{$message}}</small>
+            @enderror
         </div>
         <div class="form-group mb-4">
-          <input type="text" class="form-control rounded-0 py-3" name="subject" placeholder="Subject" required value="">
+          <input type="text" class="form-control rounded-0 py-3" name="subject" placeholder="Subject" value="{{ old('subject') }}">
+          @error('subject')
+              <small class="text-warning">{{$message}}</small>
+            @enderror
         </div>
         <div class="form-group mb-4">
-          <textarea name="message" class="form-control rounded-0" required placeholder="Message" rows="6"></textarea>
+          <textarea name="message" class="form-control rounded-0" placeholder="Message" rows="6">{{ old('message') }}</textarea>
+          @error('message')
+              <small class="text-warning">{{$message}}</small>
+            @enderror
         </div>
+        @if($errors->any())
+        <div class="alert alert-danger fade show" role="alert">
+            There were errors found!
+        </div>
+        @endif
+        @if(session('success'))
+        <div class="alert alert-success fade show" role="alert">
+            {{session('success')}}
+        </div>
+        @endif
         <button type="submit" class="btn btn-pry w-100 py-3">Submit message</button>
       </form>
     </div>

+ 34 - 6
resources/views/app/find-a-clinic.blade.php

@@ -16,6 +16,9 @@
       <h5 class="subtitle">Where can I get the Snyder HemBand System?</h5>
       <p>You’re a simple rubber band away from long-lasting hemorrhoid treatment.</p>
       <p>Over 1,000 physicians across the United States offer hemorrhoid banding to their patients.</p>
+      <div class="alert alert-warning p-3">
+        <p>Are you a physician or practice administrator that currently offers Snyder HemBand? Please contact us to be added to our directory listing.</p>
+      </div>
       <div class="row mt-5">
         <div class="col-sm-6 mb-4">
           <h5 class="header m-0">Our Office</h5>
@@ -45,25 +48,50 @@
     <div class="col-lg-6 bg-grey p-lg-5 p-4 mb-4 offset-lg-1" style="border-bottom:7px solid var(--pry-color);">
       <h4 class="subtitle">Find a Clinic</h4>
       <p class="mb-4">Please complete this brief contact form, and a Patient Care Representative will be in contact with information about trained specialists near you.</p>
-      <form class="" action="" method="post">
+      <form class="" action="{{ route('submit-find-a-clinic') }}" method="post">
         @csrf
         <div class="row">
           <div class="col-lg-6 form-group mb-4">
-            <input type="text" class="form-control rounded-0 py-3" name="fname" placeholder="First Name" required value="">
+            <input type="text" class="form-control rounded-0 py-3" name="name_first" placeholder="First Name" value="{{ old('name_first') }}" />
+            @error('name_first')
+              <small class="text-warning">{{$message}}</small>
+            @enderror
           </div>
           <div class="col-lg-6 form-group mb-4">
-            <input type="text" class="form-control rounded-0 py-3" name="lname" placeholder="Last Name" required value="">
+            <input type="text" class="form-control rounded-0 py-3" name="name_last" placeholder="Last Name" value="{{ old('name_last') }}" />
+            @error('name_last')
+              <small class="text-warning">{{$message}}</small>
+            @enderror
           </div>
         </div>
         <div class="form-group mb-4">
-          <input type="email" class="form-control rounded-0 py-3" name="email" placeholder="Email Address" required value="">
+          <input type="email" class="form-control rounded-0 py-3" name="email" placeholder="Email Address" value="{{ old('email') }}" />
+          @error('email')
+              <small class="text-warning">{{$message}}</small>
+            @enderror
         </div>
         <div class="form-group mb-4">
-          <input type="text" class="form-control rounded-0 py-3" name="phone" placeholder="Phone Number" required value="">
+          <input type="text" class="form-control rounded-0 py-3" name="phone" placeholder="Phone Number" value="{{ old('phone') }}" />
+          @error('phone')
+              <small class="text-warning">{{$message}}</small>
+            @enderror
         </div>
         <div class="form-group mb-4">
-          <input type="text" class="form-control rounded-0 py-3" name="zip" placeholder="Zip Code" required value="">
+          <input type="text" class="form-control rounded-0 py-3" name="zip" placeholder="Zip Code" value="{{ old('zip') }}" />
+          @error('zip')
+              <small class="text-warning">{{$message}}</small>
+            @enderror
+        </div>
+        @if($errors->any())
+        <div class="alert alert-danger fade show" role="alert">
+            There were errors found!
+        </div>
+        @endif
+        @if(session('success'))
+        <div class="alert alert-success fade show" role="alert">
+            {{session('success')}}
         </div>
+        @endif
         <button type="submit" class="btn btn-pry w-100 py-3">Submit</button>
       </form>
     </div>

+ 2 - 0
routes/web.php

@@ -21,4 +21,6 @@ Route::get('/post-treatment-care', [AppController::class, 'postCare'])->name('po
 Route::get('/comparing-treatment-options', [AppController::class, 'compare'])->name('compare');
 Route::get('/faqs', [AppController::class, 'faqs'])->name('faqs');
 Route::get('/find-a-clinic', [AppController::class, 'findAClinic'])->name('find-a-clinic');
+Route::post('/submit-find-a-clinic', [AppController::class, 'submitFindAClinic'])->name('submit-find-a-clinic');
 Route::get('/contact-us', [AppController::class, 'contact'])->name('contact');
+Route::post('/submit-contact-us', [AppController::class, 'submitContact'])->name('submit-contact');