fbf/laravel-contact-form

为网站添加简单联系表单的Laravel 4包

v0.1.0 2014-01-07 12:05 UTC

This package is not auto-updated.

Last update: 2024-09-24 00:32:04 UTC


README

为网站添加简单联系表单的Laravel 4包

特性

  • 联系表单的部分,您可以将其包含在自己的视图中
  • 表单字段可配置,例如姓名、电子邮件和消息
  • 处理表单提交的控制器动作,可以处理正常(重定向到前一页),或AJAX请求(以JSON格式响应状态码和消息)
  • 自定义标签、按钮、反馈消息和验证错误的翻译方法
  • 询问将被发送到单个可配置的电子邮件地址
  • 表单的Twitter Bootstrap兼容的标记和类名

安装

将以下内容添加到您的composer.json文件中

"fbf/laravel-contact-form": "dev-master"

运行

composer update

将以下内容添加到app/config/app.php文件中

'Fbf\LaravelContactForm\LaravelContactFormServiceProvider'

发布配置,然后相应地编辑它

php artisan config:publish fbf/laravel-contact-form

确保app/config/mail.php中的设置正确

配置

联系页面的URI

'uri' => 'contact',

联系页面的视图(您可以将此设置为您的应用中的一个视图,例如包含更多联系信息的视图,然后包含表单的部分,例如@include('laravel-contact-form::form')

'view' => 'laravel-contact-form::contact',

您表单的字段和规则

'fields' => array(
	'title' => array(
		'type' => 'select',
		'choices' => array(
			'' => 'Please select',
			'Mr' => 'Mr',
			'Mrs' => 'Mrs',
			'Miss' => 'Miss',
			'Ms' => 'Ms',
			'Dr' => 'Dr',
			'Other' => 'Other',
		),
	),
	'first_name' => array(
		'type' => 'text',
	),
	'last_name' => array(
		'type' => 'text',
	),
	'email' => array(
		'type' => 'text',
	),
	'enquiry' => array(
		'type' => 'textarea',
	),
),

'rules' => array(
	'title' => 'required',
	'first_name' => 'required',
	'last_name' => 'required',
	'email' => 'required|email',
	'enquiry' => 'required',
),

邮件配置选项自解释...

'mail' => array(
	'views' => array(
		'laravel-contact-form::emails.html.enquiry',
		'laravel-contact-form::emails.text.enquiry',
	),
	'to' => array(
		'name' => 'Customer Services Manager',
		'email' => 'customer.services@company.com',
	),
	'subject' => 'Website Enquiry',
),

用法

自定义配置文件中的选项,然后将以下内容添加到配置中指定的视图文件中,以在内部渲染联系表单。

@include('laravel-contact-form::form')