kgosikekana
kgosikekana

I am currently using builder to add entries to my database using a frontend form. I started using it in early 2018 however I recently did an update and now every time someone submits a form on my site it adds it as 2 entries instead of 1. Is there something in the update that has created this problem and if so what can I do to fix it?

My current plugin component looks like this:

<?php namespace Digitalmass\Jobs\Components;

use Cms\Classes\ComponentBase;

use Input;

use Validator;

use Redirect;

use Mail;

use Digitalmass\Jobs\Models\Application;

class ApplyForm extends ComponentBase
  {

  public function componentDetails(){
    return [
      'name' => 'Apply Form',
      'description' => 'Add application'
    ];

  }

  public function onSave(){

    $application = new Application();
    $application->name = Input::get('name');
    $application->surname = Input::get('surname');
    $application->contact_number = Input::get('contact_number');
    $application->email = Input::get('email');
    $application->job = Input::get('job');
    $application->cv = Input::file('cv');
    $application->save();

    $vars = ['name' => Input::get('name'),
    'contact_number' => Input::get('contact_number'),
    'email' => Input::get('email'),
    'job' => Input::get('job')];

// Admin to admin

 Mail::send('digitalmass.contact::mail.admin-application', $vars, function($message) {

    $message->to('k******@****il.com', 'Heitha Staffing Group');
    $message->subject('New Job application has been received');

     });

    return redirect('success');

  }

  }

And the frontend form looks like this:

  <form data-request="onSave" data-request-files>

    <input type="hidden" name="_handler" value="onSave">

    {{ form_token() }}
    {{ form_sessionKey() }}

    <label>Name</label>
    <input type="text" name="name">

    <label>Surname</label>
    <input type="text" name="surname">

    <label>Contact Number</label>
    <input type="text" name="contact_number">

    <label>Email Address</label>
    <input type="email" name="email">

    <label>Upload cv</label>
    <input type="file" name="cv">

    <input type="hidden" name="job" value="http://heitha.co.za/jobs/{{ record.slug }}">

    <button class="contact-btn" type="submit">Apply</button>

  </form>

Last updated

milkeshp00433068
milkeshp00433068

You are using two handlers for the same job.

form data-request="onSave" data-request-files

will fire an ajax handler to save the data.

However, you are firing the event again using

input type="hidden" name="_handler" value="onSave"

{{ form_token() }}
{{ form_sessionKey() }}

Last updated

kgosikekana
kgosikekana

Thank you so much for that milkeshp00433068. I will have a look at that and get back to you on it.

1-3 of 3