Support the ongoing development of Laravel.io →
Requests Mail
Last updated 2 years ago.
0

Looking at your code, your ajax call is executed when you change your price or quantity field but doesn't append the result to the form.

If you want to have the form send the total on submit, create a hidden input field total in your form in $.ajax().done().

$('form.calculator').append('<input type="hidden" name="total" value="' + [calculated total here] + '" />');

This way it will be submitted with the form.

0

Above answer looks good but as an aside, this is why people use things like angular, all the binding is done for you, might be worth a look if you do a lot of this sort of client side stuff.

0

flarpy said:

Above answer looks good but as an aside, this is why people use things like angular, all the binding is done for you, might be worth a look if you do a lot of this sort of client side stuff.

I tried to make this using Angular, but cannot start using Angular in Laravel. Can you pay attention to this thread http://laravel.io/forum/06-18-2016-angular-not-working-in-lara...

0

Very easy man, ajax have data attribute use it to send some data, and after it get it from request; Example:

// ajax

$.ajax({
  type: "POST",
  url: {{ route('handle_ajax') }},
  data: {data1: data1_value, data2: data2_value},
  success: function(total) {
      console.log(total) // here will incoming on acess ajax your result
  }
});

// Example controller

public function handleAjax (Request $request)
{
    dd($request->all());
    // You will get your json as array data => [ 'data_1' => 'data1_value', 'data_2' => 'data2_value'];

    // calculate and return your result as json and send emal;
    // send mail using [Laravel Events](https://laravel.com/docs/5.2/events)
    
    Event::fire(new SendEmailTotalOnResult($result));

    return json_encode($result);
}
namespace App\Events;

class SendEmailTotalOnResult extends Event
{
    private $result;

    public function __construct($result)
    {
        $this->result= $result;
    }

    public function getResult()
    {
        return $this->result;
    }
}

// Hanndle Event;

namespace App\Listeners;

use Illuminate\Contracts\Mail\Mailer;

class SendEmailEvent
{
    protected mailer;

    public function __construct(Mailer $mailer)
    {
        $this->mailer = $mailer;
    }

    public function handle(SendEmailTotalOnResult $event) {
        $data = $event->getResult();
        // send email etc.

        // For more info read [Laravel doc](https://laravel.com/docs/5.2/mail)
        $this->mailer->send('{your email tempalte}', ['data' => $data], function ($m) use ($user) {
            // data will be sended to your template..
            $m->from('[email protected]', 'Your Application');

            $m->to($user->email, $user->name)->subject('Your Email!');
        });
    }
}

P.S: Может быть я не так понял вопрос но надеюсь что помог :) И не забудьте зарегистрировать ваш 'event' в \App\Providers\EventServiceProvider.php

Last updated 7 years ago.
0

я вообще не понял зачем нужен этот Event? у меня письма отправлялись и без него

0

Sign in to participate in this thread!

Eventy

Your banner here too?

schel4ok schel4ok Joined 15 Feb 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.