Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from Dolphiq/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
johanzandstra authored Oct 16, 2017
2 parents b22c35e + 622e9f5 commit 9c198f4
Show file tree
Hide file tree
Showing 19 changed files with 322 additions and 26 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Forms Changelog

## 1.0.0 - 2017-10-16
- Initial release.

### Features
- Easy out of the box client and server side validation with use of rules in a model.
- Assign field labels in your model to use them in multiple areas.
- Easily enable/disable the form in the settings.
- Easily enable/disable logging form entries into the database in the settings.
- Control the recipient and subject of the contact requests e-mails in the plugin settings per form.
- Twig extensions, form examples and E-mail examples.
30 changes: 21 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# Form plugin for Craft CMS 3.x

Craft CMS 3 is build on top of the Yii 2 Framework.
This plugin makes it possible to use forms the way the Yii 2 Framework offers.
Craft CMS 3 is build on top of the Yii 2 Framework.
This plugin makes it possible to use forms the way the Yii 2 Framework offers. This includes:
- Easy out of the box client and server side validation with use of rules in a model.
- Assign field labels in your model to use them in multiple areas.

Next to this Yii 2 Framework logic, we added:
- Easily enable/disable the form in the settings.
- Easily enable/disable logging form entries into the database in the settings.
- Control the recipient and subject of the contact requests e-mails in the plugin settings per form.
- Twig extensions, form examples and E-mail examples.

**Note**: This plugin may become a paid add-on when the Craft Plugin store becomes available.

Expand All @@ -16,7 +24,7 @@ This plugin makes it possible to use forms the way the Yii 2 Framework offers.

2. Install plugin in the Craft Control Panel under Settings > Plugins

3. Add the directory `forms` to the root directory of your craft project (next to your config and templates directory)
3. Add a new directory `forms` to the root directory of your craft project (next to your config and templates directory) or copy the forms directory from the examples folder in the plugin directory

## Directory structure
Below you will find an example directory structure for a contact and a vacancy form
Expand Down Expand Up @@ -108,12 +116,11 @@ In this case it will be named `contact`

// Start active form
$form = ActiveForm::begin([
'action' => \craft\helpers\UrlHelper::actionUrl('dolphiq-craft3-forms/main/index', ['handle' => $handle]),
'method' => 'POST',
'options' => [
'data-pjax' => true,
],
]
'action' => \craft\helpers\UrlHelper::actionUrl('dolphiq-craft3-forms/main/index', ['handle' => $handle]),
'method' => 'POST',
'options' => [
'data-pjax' => true,
],
]);

?>
Expand Down Expand Up @@ -246,3 +253,8 @@ You can set the following options per form:
This only works when the form contains the `email` attribute so the person that fills in the form can fill in his emailadress.
You can fill in the following option:_
* Mail subject _The subject of the email that will be send to the customers emailaddress._


### Contributors & Developers
Lucas Weijers - [email protected]
Brought to you by [Dolphiq](https://dolphiq.nl)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dolphiq/craft3-forms",
"description": "Formulieren",
"description": "Craft 3 formulieren",
"version": "1.0.0",
"keywords": [
"craft",
Expand Down
35 changes: 35 additions & 0 deletions examples/forms/contact/contactForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace app\forms;

use Craft;
use plugins\dolphiq\form\models\Form;

class contactForm extends Form {

public $firstname = "";
public $lastname = "";
public $phone = "";
public $email = "";
public $message = "";

public function rules()
{
return [
[['firstname', 'lastname', 'email', 'message'], 'required'],
['email', 'email'],
['phone', 'safe']
];
}

public function attributeLabels()
{
return [
'firstname' => Craft::t('site', 'Firstname'),
'lastname' => Craft::t('site', 'Lastname'),
'phone' => Craft::t('site', 'Phone'),
'email' => Craft::t('site', 'Email'),
'message' => Craft::t('site', 'Message'),
];
}
}
11 changes: 11 additions & 0 deletions examples/forms/contact/contactMailCustomer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

/* @var $this \yii\web\View view component instance */
/* @var $message \yii\mail\BaseMessage instance of newly created mail message */
/* @var $model app\forms\contactForm */

?>
<h2>Thank you for your message <?= $model->lastname; ?></h2>
<p>
We will contact you as soon as possible
</p>
23 changes: 23 additions & 0 deletions examples/forms/contact/contactMailOwner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use yii\widgets\DetailView;

/* @var $this \yii\web\View view component instance */
/* @var $message \yii\mail\BaseMessage instance of newly created mail message */
/* @var $model \app\forms\contactForm */

?>
<h2>A contact request has been filled in</h2>
<p>
We received the following details:<br>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'firstname',
'lastname',
'email',
'phone',
'message:ntext'
]
]); ?>
</p>
7 changes: 7 additions & 0 deletions examples/forms/contact/contactThanks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
/**
* @var $model \app\forms\contactForm
*/
?>

<p>Thank you <?= $model->firstname ?>, we will contact you soon</p>
45 changes: 45 additions & 0 deletions examples/forms/contact/contactView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* @var $model app\forms\contactForm
* @var $handle string
*/

use yii\widgets\ActiveForm;
use yii\widgets\Pjax;

// Start ajax handling of the form
Pjax::begin(['enablePushState' => false, 'id' => 'pjax-'.$handle]);

// Start active form
$form = ActiveForm::begin([
'action' => \craft\helpers\UrlHelper::actionUrl('dolphiq-craft3-forms/main/index', ['handle' => $handle]),
'method' => 'POST',
'options' => [
'data-pjax' => true,
],
]);

?>

<?= $form->field($model, 'firstname')->textInput(); ?>
<?= $form->field($model, 'lastname')->textInput(); ?>
<?= $form->field($model, 'phone')->textInput(); ?>
<?= $form->field($model, 'email')->textInput(); ?>

<?= $form->field($model, 'message')->textarea(); ?>

<div>
<button type="submit">
<?= Craft::t('site', 'Send request'); ?>
</button>
</div>


<?php

// End active form
ActiveForm::end();

// End ajax handling
Pjax::end();
48 changes: 48 additions & 0 deletions examples/forms/vacancy/vacancyForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace app\forms;

use Craft;
use plugins\dolphiq\form\models\Form;

class vacancyForm extends Form {

public $vacancy = "";
public $firstname = "";
public $lastname = "";
public $phone = "";
public $email = "";
public $message = "";

public function rules()
{
return [
[['vacancy','firstname', 'lastname', 'email', 'message'], 'required'],
['email', 'email'],
['phone', 'safe']
];
}

public function attributeLabels()
{
return [
'vacancy' => Craft::t('site', 'Vacancy'),
'firstname' => Craft::t('site', 'Firstname'),
'lastname' => Craft::t('site', 'Lastname'),
'phone' => Craft::t('site', 'Phone'),
'email' => Craft::t('site', 'Email'),
'message' => Craft::t('site', 'Message'),
];
}

public function vacancyDropdown(){
$vacancies = [
Craft::t('site', 'Director'),
Craft::t('site', 'Assistant'),
Craft::t('site', 'Cleaner'),
Craft::t('site', 'Intern'),
];

return array_combine($vacancies,$vacancies);
}
}
11 changes: 11 additions & 0 deletions examples/forms/vacancy/vacancyMailCustomer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

/* @var $this \yii\web\View view component instance */
/* @var $message \yii\mail\BaseMessage instance of newly created mail message */
/* @var $model app\forms\vacancyForm */

?>
<h2>Thank you for your message <?= $model->lastname; ?></h2>
<p>
We will contact you as soon as possible
</p>
24 changes: 24 additions & 0 deletions examples/forms/vacancy/vacancyMailOwner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use yii\widgets\DetailView;

/* @var $this \yii\web\View view component instance */
/* @var $message \yii\mail\BaseMessage instance of newly created mail message */
/* @var $model \app\forms\vacancyForm */

?>
<h2>An apply for a vacancy has been received</h2>
<p>
We received the following details:<br>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'vacancy',
'firstname',
'lastname',
'email',
'phone',
'message:ntext'
]
]); ?>
</p>
11 changes: 11 additions & 0 deletions examples/forms/vacancy/vacancyThanx.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

/**
* @var $model app\forms\vacancyForm
* @var $handle string
*/

?>

<p>Thank you <?= $model->firstname; ?>! We will contact you soon.</p>

46 changes: 46 additions & 0 deletions examples/forms/vacancy/vacancyView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* @var $model app\forms\vacancyForm
* @var $handle string
*/

use yii\widgets\ActiveForm;
use yii\widgets\Pjax;

// Start ajax handling of the form
Pjax::begin(['enablePushState' => false, 'id' => 'pjax-'.$handle]);

// Start active form
$form = ActiveForm::begin([
'action' => \craft\helpers\UrlHelper::actionUrl('dolphiq-craft3-forms/main/index', ['handle' => $handle]),
'method' => 'POST',
'options' => [
'data-pjax' => true,
],
]);

?>

<?= $form->field($model, 'vacancy')->dropDownList($model->vacancyDropdown()); ?>
<?= $form->field($model, 'firstname')->textInput(); ?>
<?= $form->field($model, 'lastname')->textInput(); ?>
<?= $form->field($model, 'phone')->textInput(); ?>
<?= $form->field($model, 'email')->textInput(); ?>

<?= $form->field($model, 'message')->textarea(); ?>

<div>
<button type="submit">
<?= Craft::t('site', 'Apply'); ?>
</button>
</div>


<?php

// End active form
ActiveForm::end();

// End ajax handling
Pjax::end();
8 changes: 3 additions & 5 deletions src/Plugin.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?php
/**
* Created by PhpStorm.
* User: lucasweijers
* Date: 19-05-17
* Time: 15:23
* Created by Dolphiq
* Lucas Weijers
* Date: 2017-10-16
*/


namespace plugins\dolphiq\form;

use Craft;
Expand Down
9 changes: 5 additions & 4 deletions src/assets/pjaxAsset.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

/**
* Created by PhpStorm.
* User: lucasweijers
* Date: 28-08-17
* Time: 15:08
* Created by Dolphiq
* Lucas Weijers
* Date: 2017-10-16
*/

namespace plugins\dolphiq\form\assets;
Expand All @@ -20,5 +20,6 @@ class pjaxAsset extends AssetBundle

public $depends = [
'yii\web\JqueryAsset',
'yii\widgets\PjaxAsset'
];
}
Loading

0 comments on commit 9c198f4

Please sign in to comment.