Integrating Simple Web Form Laravel

I am trying to make a simple webform using laravel and trying to decode the api docs. If i have to create a form, i will need to create 3 api requests.

  1. Create Organization
  2. Create Person under that Organization
  3. Create Deal under that Person.

I was wondering that laravel wrapper by Devio should be able to cover this, or do i need guzzle or Zttp to create three requests everytime.

Thanks in advance.

Hi @manshu,
you can use the wrapper. It’s very simple:

// instantiate $pipedrive like shown in the documentation

$organization = $pipedrive->organizations->add(['name' => 'New Organization']);
$person = $pipedrive->persons->add(['name' => 'John Doe', 'org_id' => $organization->getData()->id]);
$deal = $pipedrive->deals->add(['title' => 'Amazing Deal', 'person_id' => $person->getData()->id]); 

To instantiate and authorize, you can look at the documentation: https://github.com/IsraelOrtuno/pipedrive

:metal:

1 Like

Finally created a video. If anyone is looking to do this. https://youtu.be/BH95Wz9dwns

1 Like

To integrate a simple web form in Laravel, you can follow these steps:

  1. Create a Route: Define a route in your routes/web.php file to handle the form submission and display the form:

    Route::get('/contact', 'ContactController@showForm');
    Route::post('/contact', 'ContactController@submitForm');
    
  2. Create a Controller: Generate a controller using Artisan to handle the form logic:

    php artisan make:controller ContactController
    
  3. Implement Controller Methods: In your ContactController, define the showForm method to display the form and the submitForm method to process the form submission:

    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    
    class ContactController extends Controller
    {
        public function showForm()
        {
            return view('contact');
        }
    
        public function submitForm(Request $request)
        {
            // Process form submission
            // You can access form data using $request->input('field_name')
            // For example, $request->input('name') to access the 'name' field
        }
    }
    
  4. Create a View: Create a view file (resources/views/contact.blade.php) to display the form:

    <form method="POST" action="/contact">
        @csrf
        <label for="name">Name:</label><br>
        <input type="text" id="name" name="name"><br>
    
        <label for="email">Email:</label><br>
        <input type="email" id="email" name="email"><br>
    
        <label for="message">Message:</label><br>
        <textarea id="message" name="message"></textarea><br>
    
        <button type="submit">Submit</button>
    </form>
    
  5. Handle Form Submission: In the submitForm method of your ContactController, process the form submission (e.g., send an email, save to database, etc.):

    use Illuminate\Support\Facades\Mail;
    use App\Mail\ContactFormSubmitted;
    
    public function submitForm(Request $request)
    {
        // Validate form data
        $validatedData = $request->validate([
            'name' => 'required|string|max:255',
            'email' => 'required|email',
            'message' => 'required',
        ]);
    
        // Process form submission (e.g., send email)
        Mail::to('you@example.com')->send(new ContactFormSubmitted($validatedData));
    
        return redirect('/contact')->with('success', 'Form submitted successfully!');
    }
    
  6. Set Up Mail Configuration: Configure your mail driver in the .env file and set up your mail settings in config/mail.php.

  7. Display Success Message: Update your contact.blade.php view to display a success message if the form is submitted successfully:

    @if(session('success'))
        <div class="alert alert-success">
            {{ session('success') }}
        </div>
    @endif
    
  8. Run Your Application: Run your Laravel application (php artisan serve) and navigate to the /contact route to see your form in action ATI EXAMS.

This is a basic example of how to integrate a simple web form in Laravel. You can expand on this example by adding form validation, error handling, and more complex form processing logic as needed.