Skip to content

Commit f483de5

Browse files
Simon BranSimon Bran
authored andcommitted
Fix version
1 parent 93905c2 commit f483de5

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

ArrayHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ public static function multisort(&$array, $key, $direction = SORT_ASC, $sortFlag
616616
public static function htmlEncode($data, $valuesOnly = true, $charset = null)
617617
{
618618
if ($charset === null) {
619-
$charset = Yii::$app ? Yii::$app->charset : 'UTF-8';
619+
$charset = 'UTF-8';
620620
}
621621
$d = [];
622622
foreach ($data as $key => $value) {

Html.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,66 @@ private static function wrapIntoCondition($content, $condition)
290290
}
291291
return "<!--[if $condition]>\n" . $content . "\n<![endif]-->";
292292
}
293+
294+
/**
295+
* Generates a form start tag.
296+
* @param array|string $action the form action URL. This parameter will be processed by [[Url::to()]].
297+
* @param string $method the form submission method, such as "post", "get", "put", "delete" (case-insensitive).
298+
* Since most browsers only support "post" and "get", if other methods are given, they will
299+
* be simulated using "post", and a hidden input will be added which contains the actual method type.
300+
* See [[\yii\web\Request::methodParam]] for more details.
301+
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
302+
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
303+
* If a value is null, the corresponding attribute will not be rendered.
304+
* See [[renderTagAttributes()]] for details on how attributes are being rendered.
305+
*
306+
* Special options:
307+
*
308+
* - `csrf`: whether to generate the CSRF hidden input. Defaults to true.
309+
*
310+
* @return string the generated form start tag.
311+
* @see endForm()
312+
*/
313+
public static function beginForm($action = '', $method = 'post', $options = [])
314+
{
315+
$action = self::url($action);
316+
317+
$hiddenInputs = [];
318+
if (!strcasecmp($method, 'get') && ($pos = strpos($action, '?')) !== false) {
319+
// query parameters in the action are ignored for GET method
320+
// we use hidden fields to add them back
321+
foreach (explode('&', substr($action, $pos + 1)) as $pair) {
322+
if (($pos1 = strpos($pair, '=')) !== false) {
323+
$hiddenInputs[] = static::hiddenInput(
324+
urldecode(substr($pair, 0, $pos1)),
325+
urldecode(substr($pair, $pos1 + 1))
326+
);
327+
} else {
328+
$hiddenInputs[] = static::hiddenInput(urldecode($pair), '');
329+
}
330+
}
331+
$action = substr($action, 0, $pos);
332+
}
333+
334+
$options['action'] = $action;
335+
$options['method'] = $method;
336+
$form = static::beginTag('form', $options);
337+
if (!empty($hiddenInputs)) {
338+
$form .= "\n" . implode("\n", $hiddenInputs);
339+
}
340+
341+
return $form;
342+
}
343+
344+
/**
345+
* Generates a form end tag.
346+
* @return string the generated tag
347+
* @see beginForm()
348+
*/
349+
public static function endForm()
350+
{
351+
return '</form>';
352+
}
293353

294354
/**
295355
* Generates a hyperlink tag.

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# opencart-html-helper
22
Opencart Html Helper provides a set of static methods for generating commonly used HTML tags.
33
###
4-
This module from Yii2 Framework is adapted by *Mefistophell Nill* and *Zoturn* (**8sun Empire**) especially for OpenCart.
4+
This module from Yii2 Framework is adapted by [Mefistophell Nill](https://github.com/Mefistophell) and [Zoturn](https://github.com/Zoturn) (**8sun Empire**) especially for OpenCart.
55

6-
>WARNING: Not all methods are tested for today!
6+
>This module includes another module from Yii2, which we adapted and you can use it separately. Link on the module and on is below.
7+
8+
>[ArrayHelper](https://github.com/8sun/opencart-array-helper) - provides additional array functionality that you can use in your application.
79
810
Tested on Opencart 2.0. If you find an error, let us know.
911

10-
Version: 0.8.0
12+
Version: 0.9.0
1113

1214
## Install
1315
1. You need copy the files to `/system/helper/` directory.

0 commit comments

Comments
 (0)