Skip to content

Commit

Permalink
Added new submit option
Browse files Browse the repository at this point in the history
Added new submit option to allow prevention of submit of field for PCI
compliance by exclusion of the name attribute.

Refactor to extend widgets from new InputWidget class
  • Loading branch information
Andrew Blake committed Jun 28, 2016
1 parent 460b9c7 commit fac5907
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 307 deletions.
9 changes: 8 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
version 1.1.1
=============
**Date:** 29-Jun-2016

1. Added new "submit" option that when set to false will not add the name attribute into the input.
2. Refactored to extend form new InputWidget class.

version 1.1.0
=============
**Date:** 23-Mar-2016
**Date:** 17-Jun-2016

1. BC: Changed CreditCardModel for just CreditCard. Re-factored a little within here.
2. Remove default placeholder from each of the fields as can be added in in standard way within Options.
Expand Down
2 changes: 1 addition & 1 deletion CreditCardAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package andrewblake1\yii2-credit-card
* @license https://github.com/andrewblake1/yii2-credit-card/blob/master/LICENSE.md MIT License
* @link https://github.com/andrewblake1/yii2-credit-card
* @version 1.1.0
* @version 1.1.1
*/
namespace andrewblake1\creditcard;

Expand Down
103 changes: 3 additions & 100 deletions CreditCardCVCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package andrewblake1\yii2-credit-card
* @license https://github.com/andrewblake1/yii2-credit-card/blob/master/LICENSE.md MIT License
* @link https://github.com/andrewblake1/yii2-credit-card
* @version 1.1.0
* @version 1.1.1
*/
namespace andrewblake1\creditcard;

Expand All @@ -18,109 +18,12 @@
*
* @author Andrew Blake <[email protected]>
*/
class CreditCardCVCode extends \kartik\base\InputWidget
class CreditCardCVCode extends InputWidget
{
/**
* @var string/boolean the addon content
*/
public $addon = null;

/**
* @var array HTML attributes for the addon container
* the following special options are identified
* - asButton: boolean if the addon is to be displayed as a button.
* - buttonOptions: array HTML attributes if the addon is to be
* displayed like a button. If [[asButton]] is true, this will
* default to ['class' => 'btn btn-default']
*/
public $addonOptions = [];

/**
* @var string use [[right]] or [[left]] type of addon
* position near to input
*/
public $addonPosition = 'right';

/**
* @var array HTML attributes for the input group container
*/
public $containerOptions = [];

public $type = 'tel';
public $autocomplete = null;

public function init()
{
parent::init();
$this->_msgCat = 'creditcard';
$this->initI18N(__DIR__);

$this->options['type'] = $this->type;
$this->options['autocomplete'] = $this->autocomplete;

$this->registerAssets();
}

public function run()
{
return Html::tag('div', $this->renderInput(), $this->containerOptions);
}

/**
* This is largely copied from kartik\time\TimePicker
* @return string
*/
protected function renderInput()
{
Html::addCssClass($this->options, 'form-control');
if (!empty($this->options['disabled'])) {
Html::addCssClass($this->addonOptions, 'disabled-addon');
}
if (ArrayHelper::getValue($this->pluginOptions, 'template', true) === false) {
if (isset($this->size)) {
Html::addCssClass($this->options, 'input-' . $this->size);
Html::addCssClass($this->addonOptions, 'inline-addon inline-addon-' . $this->size);
} else {
Html::addCssClass($this->addonOptions, 'inline-addon');
}
return $this->getInput('textInput') . Html::tag('span', $this->addon, $this->addonOptions);
}
Html::addCssClass($this->containerOptions, 'input-group');
$asButton = ArrayHelper::remove($this->addonOptions, 'asButton', false);
$buttonOptions = ArrayHelper::remove($this->addonOptions, 'buttonOptions', []);
if ($asButton) {
Html::addCssClass($this->addonOptions, 'input-group-btn picker');
$buttonOptions['type'] = 'button';
if (empty($buttonOptions['class'])) {
Html::addCssClass($buttonOptions, 'btn btn-default');
}
$content = Html::button($this->addon, $buttonOptions);
} else {
Html::addCssClass($this->addonOptions, 'input-group-addon picker');
$content = $this->addon;
}
$addon = $this->addon
? Html::tag('span', $content, $this->addonOptions)
: null;
if (isset($this->size)) {
Html::addCssClass($this->containerOptions, 'input-group-' . $this->size);
}
switch($this->addonPosition) {
default:
case 'left':
return $addon . $this->getInput('textInput');
break;

case 'right':
return $this->getInput('textInput') . $addon;
break;
}
}

public function registerAssets()
{
$view = $this->getView();
CreditCardAsset::register($view);
parent::registerAssets();
$this->registerPlugin('ccCVC');
}

Expand Down
102 changes: 3 additions & 99 deletions CreditCardExpiry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package andrewblake1\yii2-credit-card
* @license https://github.com/andrewblake1/yii2-credit-card/blob/master/LICENSE.md MIT License
* @link https://github.com/andrewblake1/yii2-credit-card
* @version 1.1.0
* @version 1.1.1
*/
namespace andrewblake1\creditcard;

Expand All @@ -18,109 +18,13 @@
*
* @author Andrew Blake <[email protected]>
*/
class CreditCardExpiry extends \kartik\base\InputWidget
class CreditCardExpiry extends InputWidget
{
/**
* @var string/boolean the addon content
*/
public $addon = false;

/**
* @var array HTML attributes for the addon container
* the following special options are identified
* - asButton: boolean if the addon is to be displayed as a button.
* - buttonOptions: array HTML attributes if the addon is to be
* displayed like a button. If [[asButton]] is true, this will
* default to ['class' => 'btn btn-default']
*/
public $addonOptions = [];

/**
* @var string use [[right]] or [[left]] type of addon
* position near to input
*/
public $addonPosition = 'right';

/**
* @var array HTML attributes for the input group container
*/
public $containerOptions = [];

public $type = 'tel';
public $autocomplete = 'cc-expiry';

public function init()
{
parent::init();
$this->_msgCat = 'creditcard';
$this->initI18N(__DIR__);

$this->options['type'] = $this->type;
$this->options['autocomplete'] = $this->autocomplete;

$this->registerAssets();
}

public function run()
{
return Html::tag('div', $this->renderInput(), $this->containerOptions);
}

/**
* This is largely copied from kartik\time\TimePicker
* @return string
*/
protected function renderInput()
{
Html::addCssClass($this->options, 'form-control');
if (!empty($this->options['disabled'])) {
Html::addCssClass($this->addonOptions, 'disabled-addon');
}
if (ArrayHelper::getValue($this->pluginOptions, 'template', true) === false) {
if (isset($this->size)) {
Html::addCssClass($this->options, 'input-' . $this->size);
Html::addCssClass($this->addonOptions, 'inline-addon inline-addon-' . $this->size);
} else {
Html::addCssClass($this->addonOptions, 'inline-addon');
}
return $this->getInput('textInput') . Html::tag('span', $this->addon, $this->addonOptions);
}
Html::addCssClass($this->containerOptions, 'input-group');
$asButton = ArrayHelper::remove($this->addonOptions, 'asButton', false);
$buttonOptions = ArrayHelper::remove($this->addonOptions, 'buttonOptions', []);
if ($asButton) {
Html::addCssClass($this->addonOptions, 'input-group-btn picker');
$buttonOptions['type'] = 'button';
if (empty($buttonOptions['class'])) {
Html::addCssClass($buttonOptions, 'btn btn-default');
}
$content = Html::button($this->addon, $buttonOptions);
} else {
Html::addCssClass($this->addonOptions, 'input-group-addon picker');
$content = $this->addon;
}
$addon = $this->addon
? Html::tag('span', $content, $this->addonOptions)
: null;
if (isset($this->size)) {
Html::addCssClass($this->containerOptions, 'input-group-' . $this->size);
}
switch($this->addonPosition) {
default:
case 'left':
return $addon . $this->getInput('textInput');
break;

case 'right':
return $this->getInput('textInput') . $addon;
break;
}
}

public function registerAssets()
{
$view = $this->getView();
CreditCardAsset::register($view);
parent::registerAssets();
$this->registerPlugin('ccExpiry');
}

Expand Down
101 changes: 4 additions & 97 deletions CreditCardNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package andrewblake1\yii2-credit-card
* @license https://github.com/andrewblake1/yii2-credit-card/blob/master/LICENSE.md MIT License
* @link https://github.com/andrewblake1/yii2-credit-card
* @version 1.1.0
* @version 1.1.1
*/
namespace andrewblake1\creditcard;

Expand All @@ -18,109 +18,16 @@
*
* @author Andrew Blake <[email protected]>
*/
class CreditCardNumber extends \kartik\base\InputWidget
class CreditCardNumber extends InputWidget
{
/**
* @var string/boolean the addon content
*/
public $addon = '<i class="fa fa-lg fa-credit-card"></i>';

/**
* @var array HTML attributes for the addon container
* the following special options are identified
* - asButton: boolean if the addon is to be displayed as a button.
* - buttonOptions: array HTML attributes if the addon is to be
* displayed like a button. If [[asButton]] is true, this will
* default to ['class' => 'btn btn-default']
*/
public $addonOptions = [];

/**
* @var string use [[right]] or [[left]] type of addon
* position near to input
*/
public $addonPosition = 'right';

/**
* @var array HTML attributes for the input group container
*/
public $containerOptions = [];
public $addon = '<i class="fa fa-lg fa-credit-card"></i>';

public $type = 'tel';
public $autocomplete = 'cc-number';

public function init()
{
parent::init();
$this->_msgCat = 'creditcard';
$this->initI18N(__DIR__);

$this->options['type'] = $this->type;
$this->options['autocomplete'] = $this->autocomplete;

$this->registerAssets();
}

public function run()
{
return Html::tag('div', $this->renderInput(), $this->containerOptions);
}

/**
* This is largely copied from kartik\time\TimePicker
* @return string
*/
protected function renderInput()
{
Html::addCssClass($this->options, 'form-control');
if (!empty($this->options['disabled'])) {
Html::addCssClass($this->addonOptions, 'disabled-addon');
}
if (ArrayHelper::getValue($this->pluginOptions, 'template', true) === false) {
if (isset($this->size)) {
Html::addCssClass($this->options, 'input-' . $this->size);
Html::addCssClass($this->addonOptions, 'inline-addon inline-addon-' . $this->size);
} else {
Html::addCssClass($this->addonOptions, 'inline-addon');
}
return $this->getInput('textInput') . Html::tag('span', $this->addon, $this->addonOptions);
}
Html::addCssClass($this->containerOptions, 'input-group');
$asButton = ArrayHelper::remove($this->addonOptions, 'asButton', false);
$buttonOptions = ArrayHelper::remove($this->addonOptions, 'buttonOptions', []);
if ($asButton) {
Html::addCssClass($this->addonOptions, 'input-group-btn picker');
$buttonOptions['type'] = 'button';
if (empty($buttonOptions['class'])) {
Html::addCssClass($buttonOptions, 'btn btn-default');
}
$content = Html::button($this->addon, $buttonOptions);
} else {
Html::addCssClass($this->addonOptions, 'input-group-addon picker');
$content = $this->addon;
}
$addon = $this->addon
? Html::tag('span', $content, $this->addonOptions)
: null;
if (isset($this->size)) {
Html::addCssClass($this->containerOptions, 'input-group-' . $this->size);
}
switch($this->addonPosition) {
default:
case 'left':
return $addon . $this->getInput('textInput');
break;

case 'right':
return $this->getInput('textInput') . $addon;
break;
}
}

public function registerAssets()
{
$view = $this->getView();
CreditCardAsset::register($view);
parent::registerAssets();
$this->registerPlugin('ccNumber');
}

Expand Down
2 changes: 1 addition & 1 deletion FontAwesomeAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package andrewblake1\yii2-credit-card
* @license https://github.com/andrewblake1/yii2-credit-card/blob/master/LICENSE.md MIT License
* @link https://github.com/andrewblake1/yii2-credit-card
* @version 1.1.0
* @version 1.1.1
*/
namespace andrewblake1\creditcard;

Expand Down
Loading

0 comments on commit fac5907

Please sign in to comment.