airdev/contact

一个快速提供联系表单和电子邮件发送功能的软件包。

安装: 61

依赖项: 0

建议者: 0

安全性: 0

星级: 0

关注者: 1

分支: 0

开放问题: 0

语言:Blade

v1.2.3 2021-08-10 06:58 UTC

This package is auto-updated.

Last update: 2024-09-10 13:51:44 UTC


README

一个快速提供联系表单和电子邮件发送功能的软件包。

它只适用于Airdev web基础项目。

使用方法

安装

composer require airdev/contact

接下来,将其添加到config/app.php中Laravel的包提供者

/*
 * Package Service Providers...
 */
Airdev\Contact\AirdevContactProvider::class,

将Google Recaptcha api添加到您的app.blade.php中

<script src="https://www.google.com/recaptcha/api.js"></script>

发布配置文件

php artisan vendor:publish --tag=airdev-contact-config

接下来,您需要在config/contact.php中更新一些配置

/* config/contact.php */

return [
    /**
     * To publish config file run :
     * php artisan vendor:publish --tag=airdev-contact-config
     */

    'debug' => false,

    // Class to apply on the submit button (by default, Bootstrap 5 btn classes are used)
    'submit-btn-class' => 'btn btn-primary',
    // Class to apply on <form>
    'form-class' => '',

    // The google captcha keys
    'captcha_secret' => env('CAPTCHA_SECRET', ''),
    'captcha_public' => env('CAPTCHA_PUBLIC', ''),

    'mails' => [
        'contact' => [ // it will generate post route 'contact_post'
            // The address that should receive the sent mail
            'mail_to' => env('MAIL_TO', ''),

            // Subject of the mail
            'mail_subject' => 'Contact du site ' . env('APP_NAME', ''),

            // Redirection after sended the mail
            'redirect' => '/',

            // The mail view to use (you can publish default view to base on and copy it into your resource folder
            'view' => 'mails.mail',
        ],

        /*
         * Just delete this if you have only one form
         */
        'depannage' => [ // it will generate post route 'depannage_post'
            'mail_to' => env('MAIL_TO', ''),
            'mail_subject' => 'Demande de dépannage du site ' . env('APP_NAME', ''),
            'redirect' => '/',
            'view' => 'mails.depannage',
        ]
    ],
];

将blade组件调用到您的视图中

并指定在config/contact.php中定义的路由名称

<x-airdev-contact::form routeName="contact"></x-airdev-contact::form>
<x-airdev-contact::form routeName="depannage"></x-airdev-contact::form>

您可以编辑默认字段和发送按钮

<x-airdev-contact::form>
    <!--  Editing the fields  -->
    <div>
        <label for="input_name">Nom</label>
        <input required name="name" type="text" id="input_name" placeholder="Votre nom">
    </div>
    <div>
        <label for="input_email">Email</label>
        <input name="email" required type="email" id="input_email" placeholder="Votre email">
    </div>
    <div>
        <label for="input_address">Adresse</label>
        <input name="address" type="text" id="input_address" placeholder="Votre adresse">
    </div>
    <div>
        <label for="input_phone">Téléphone</label>
        <input name="phone" required type="text" id="input_phone" placeholder="Votre téléphone">
    </div>
    <div>
        <label for="input_message">Votre message</label>
        <textarea name="message" id="input_message" placeholder="Votre message"></textarea>
    </div>

    <!--  Editing the sending button  -->
    <x-slot name="button_slot">
        <a href="#" class="link">ENVOYER</a>
    </x-slot>
</x-airdev-contact::form>

您可以为<form><button>添加自定义类

您将在发布的配置文件config/contact.php中找到这些设置

/* config/contact.php */

return [
    // Class to apply on the submit button (by default, Bootstrap 5 btn classes are used)
    'submit-btn-class' => 'btn btn-primary',
    // Class to apply on <form>
    'form-class' => ''
];

可选自定义

以下其他自定义并非此库正常工作所必需。

发布邮件视图

如果您想编辑发送的邮件,您可以发布视图文件。这通常是库中有比基本字段更多字段的情况。

php artisan vendor:publish --tag=airdev-contact-mail-view

您现在可以修改以下文件中的视图

resources/views/vendor/airdev/contact/mails/mail.blade.php