Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/Config/DocTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@ class DocTypes
'xhtml-rdfa-1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
'xhtml-rdfa-2' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">',
];

/**
* Endline HTML Tag
*
* This setting is for html and form helpers.
*
* For :
* - `<input>`
* - `<img>`
Comment thread
ddevsr marked this conversation as resolved.
*/
public bool $xhtml = false;
Comment thread
paulbalandan marked this conversation as resolved.
Comment thread
ddevsr marked this conversation as resolved.
}
19 changes: 19 additions & 0 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,25 @@ function function_usable(string $functionName): bool
}
}

if (! function_exists('htmltag_endline')) {
Comment thread
paulbalandan marked this conversation as resolved.
/**
* Endline HTML Tag
*
* Generates endline html tag by document type
*/
function htmltag_endline(): string
Comment thread
kenjis marked this conversation as resolved.
Comment thread
paulbalandan marked this conversation as resolved.
{
$config = config('DocTypes');
$doctype = $config->xhtml;
Comment thread
ddevsr marked this conversation as resolved.

if ($doctype) {
return '/>';
}

return '>';
}
}

if (! function_exists('helper')) {
/**
* Loads a helper file into memory. Supports namespaced helpers,
Expand Down
6 changes: 3 additions & 3 deletions system/Helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function form_input($data = '', string $value = '', $extra = '', string $type =
'value' => $value,
];

return '<input ' . parse_form_attributes($data, $defaults) . stringify_attributes($extra) . " />\n";
return '<input ' . parse_form_attributes($data, $defaults) . stringify_attributes($extra) . htmltag_endline() . "\n";
}
}

Expand Down Expand Up @@ -194,7 +194,7 @@ function form_upload($data = '', string $value = '', $extra = ''): string

$data['type'] = 'file';

return '<input ' . parse_form_attributes($data, $defaults) . stringify_attributes($extra) . " />\n";
return '<input ' . parse_form_attributes($data, $defaults) . stringify_attributes($extra) . htmltag_endline() . "\n";
}
}

Expand Down Expand Up @@ -365,7 +365,7 @@ function form_checkbox($data = '', string $value = '', bool $checked = false, $e
$defaults['checked'] = 'checked';
}

return '<input ' . parse_form_attributes($data, $defaults) . stringify_attributes($extra) . " />\n";
return '<input ' . parse_form_attributes($data, $defaults) . stringify_attributes($extra) . htmltag_endline() . "\n";
}
}

Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/html_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function img($src = '', bool $indexPage = false, $attributes = ''): string
unset($attributes['alt'], $attributes['src']);
}

return $img . stringify_attributes($attributes) . ' />';
return $img . stringify_attributes($attributes) . htmltag_endline();
}
}

Expand Down
42 changes: 21 additions & 21 deletions tests/system/Helpers/FormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function testFormOpenWithoutAction()
$Name = csrf_token();
$expected = <<<EOH
<form action="http://example.com/index.php" name="form" id="form" method="POST" accept-charset="utf-8">
<input type="hidden" name="{$Name}" value="{$Value}" style="display:none;" />
<input type="hidden" name="{$Name}" value="{$Value}" style="display:none;">

EOH;
} else {
Expand All @@ -128,7 +128,7 @@ public function testFormOpenWithoutMethod()
$Name = csrf_token();
$expected = <<<EOH
<form action="http://example.com/index.php/foo/bar" name="form" id="form" method="post" accept-charset="utf-8">
<input type="hidden" name="{$Name}" value="{$Value}" style="display:none;" />
<input type="hidden" name="{$Name}" value="{$Value}" style="display:none;">

EOH;
} else {
Expand All @@ -155,15 +155,15 @@ public function testFormOpenWithHidden()
$Name = csrf_token();
$expected = <<<EOH
<form action="http://example.com/index.php/foo/bar" name="form" id="form" method="POST" accept-charset="utf-8">
<input type="hidden" name="foo" value="bar" />
<input type="hidden" name="{$Name}" value="{$Value}" />
<input type="hidden" name="foo" value="bar">
<input type="hidden" name="{$Name}" value="{$Value}">

EOH;
} else {
$expected = <<<'EOH'
<form action="http://example.com/index.php/foo/bar" name="form" id="form" method="POST" accept-charset="utf-8">

<input type="hidden" name="foo" value="bar" />
<input type="hidden" name="foo" value="bar">

EOH;
}
Expand All @@ -189,7 +189,7 @@ public function testFormOpenMultipart()
$Name = csrf_token();
$expected = <<<EOH
<form action="http://example.com/index.php/foo/bar" name="form" id="form" method="POST" enctype="multipart/form-data" accept-charset="utf-8">
<input type="hidden" name="{$Name}" value="{$Value}" style="display:none;" />
<input type="hidden" name="{$Name}" value="{$Value}" style="display:none;">

EOH;
} else {
Expand All @@ -214,7 +214,7 @@ public function testFormHidden()
{
$expected = <<<EOH

<input type="hidden" name="username" value="johndoe" />\n
<input type="hidden" name="username" value="johndoe">\n
EOH;
$this->assertSame($expected, form_hidden('username', 'johndoe'));
}
Expand All @@ -226,7 +226,7 @@ public function testFormHiddenArrayInput()
];
$expected = <<<'EOH'

<input type="hidden" name="foo" value="bar" />
<input type="hidden" name="foo" value="bar">

EOH;
$this->assertSame($expected, form_hidden($data, null));
Expand All @@ -239,7 +239,7 @@ public function testFormHiddenArrayValues()
];
$expected = <<<'EOH'

<input type="hidden" name="name[foo]" value="bar" />
<input type="hidden" name="name[foo]" value="bar">

EOH;
$this->assertSame($expected, form_hidden('name', $data));
Expand All @@ -248,7 +248,7 @@ public function testFormHiddenArrayValues()
public function testFormInput()
{
$expected = <<<EOH
<input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%" />\n
<input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%">\n
EOH;
$data = [
'name' => 'username',
Expand All @@ -264,7 +264,7 @@ public function testFormInput()
public function testFormInputWithExtra()
{
$expected = <<<EOH
<input type="email" name="identity" value="" id="identity" class="form-control form-control-lg" />\n
<input type="email" name="identity" value="" id="identity" class="form-control form-control-lg">\n
EOH;
$data = [
'id' => 'identity',
Expand All @@ -280,15 +280,15 @@ public function testFormInputWithExtra()
public function testFormPassword()
{
$expected = <<<EOH
<input type="password" name="password" value="" />\n
<input type="password" name="password" value="">\n
EOH;
$this->assertSame($expected, form_password('password'));
}

public function testFormUpload()
{
$expected = <<<EOH
<input type="file" name="attachment" />\n
<input type="file" name="attachment">\n
EOH;
$this->assertSame($expected, form_upload('attachment'));
}
Expand Down Expand Up @@ -612,7 +612,7 @@ public function testFormFieldsetClose()
public function testFormCheckbox()
{
$expected = <<<EOH
<input type="checkbox" name="newsletter" value="accept" checked="checked" />\n
<input type="checkbox" name="newsletter" value="accept" checked="checked">\n
EOH;
$this->assertSame($expected, form_checkbox('newsletter', 'accept', true));
Comment thread
kenjis marked this conversation as resolved.
}
Expand All @@ -625,7 +625,7 @@ public function testFormCheckboxArrayData()
'checked' => true,
];
$expected = <<<'EOH'
<input type="checkbox" name="foo" value="bar" checked="checked" />
<input type="checkbox" name="foo" value="bar" checked="checked">

EOH;
$this->assertSame($expected, form_checkbox($data));
Expand All @@ -639,7 +639,7 @@ public function testFormCheckboxArrayDataWithCheckedFalse()
'checked' => false,
];
$expected = <<<'EOH'
<input type="checkbox" name="foo" value="bar" />
<input type="checkbox" name="foo" value="bar">

EOH;
$this->assertSame($expected, form_checkbox($data));
Expand All @@ -648,15 +648,15 @@ public function testFormCheckboxArrayDataWithCheckedFalse()
public function testFormRadio()
{
$expected = <<<EOH
<input type="radio" name="newsletter" value="accept" checked="checked" />\n
<input type="radio" name="newsletter" value="accept" checked="checked">\n
EOH;
$this->assertSame($expected, form_radio('newsletter', 'accept', true));
}

public function testFormSubmit()
{
$expected = <<<EOH
<input type="submit" name="mysubmit" value="Submit Post!" />\n
<input type="submit" name="mysubmit" value="Submit Post!">\n
EOH;
$this->assertSame($expected, form_submit('mysubmit', 'Submit Post!'));
}
Expand All @@ -683,7 +683,7 @@ public function testFormLabelWithAttributes()
public function testFormReset()
{
$expected = <<<EOH
<input type="reset" name="myreset" value="Reset" />\n
<input type="reset" name="myreset" value="Reset">\n
EOH;
$this->assertSame($expected, form_reset('myreset', 'Reset'));
}
Expand Down Expand Up @@ -724,7 +724,7 @@ public function testFormDatalist()
'bar1',
];
$expected = <<<'EOH'
<input type="text" name="foo" value="bar" list="foo_list" />
<input type="text" name="foo" value="bar" list="foo_list">

<datalist id='foo_list'><option value='foo1'>
<option value='bar1'>
Expand Down Expand Up @@ -943,7 +943,7 @@ public function testValidationShowError()

$html = validation_show_error('id');

$this->assertSame('<span class="help-block">The ID field is required.</span>' . "\n", $html);
$this->assertSame('<span class="help-block">The ID field is required.</span>' . PHP_EOL, $html);
Comment thread
kenjis marked this conversation as resolved.
}

public function testFormParseFormAttributesTrue()
Expand Down
6 changes: 3 additions & 3 deletions tests/system/Helpers/HTMLHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,21 @@ public function testMultiLevelOL()
public function testIMG()
{
$target = 'http://site.com/images/picture.jpg';
$expected = '<img src="http://site.com/images/picture.jpg" alt="" />';
$expected = '<img src="http://site.com/images/picture.jpg" alt="">';
$this->assertSame($expected, img($target));
}

public function testIMGWithoutProtocol()
{
$target = 'assets/mugshot.jpg';
$expected = '<img src="http://example.com/assets/mugshot.jpg" alt="" />';
$expected = '<img src="http://example.com/assets/mugshot.jpg" alt="">';
$this->assertSame($expected, img($target));
}

public function testIMGWithIndexpage()
{
$target = 'assets/mugshot.jpg';
$expected = '<img src="http://example.com/index.php/assets/mugshot.jpg" alt="" />';
$expected = '<img src="http://example.com/index.php/assets/mugshot.jpg" alt="">';
$this->assertSame($expected, img($target, true));
}

Expand Down
4 changes: 4 additions & 0 deletions user_guide_src/source/changelogs/v4.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ For example, the Exit code has been changed like the following:
Others
------

- Now ``form_helper``, ``html_helper`` and common functions have been changed to appear void HTML elements (e.g. ``<input>``) with valid HTML5 by default.
- The ``spark`` file has been changed due to a change in the processing of Spark commands.
- ``InvalidArgumentException`` that is a kind of ``LogicException`` in ``BaseBuilder::_whereIn()`` is not suppressed by the configuration. Previously if ``CI_DEBUG`` was false, the exception was suppressed.
- The data structure returned by :ref:`BaseConnection::getForeignKeyData() <metadata-getforeignkeydata>` has been changed.
Expand Down Expand Up @@ -211,6 +212,9 @@ Libraries
Helpers and Functions
=====================

- Creation of void HTML elements like ``<input>`` via ``form_helper``, ``html_helper`` or common functions can be configured to exclude
or not the solidus character (``/``) before the right angle bracket (``>``) by setting the ``$html5`` property in
**app/Config/DocTypes.php** to ``true``.
- Now you can autoload helpers by **app/Config/Autoload.php**.
- Added new Form helper function :php:func:`validation_errors()`, :php:func:`validation_list_errors()` and :php:func:`validation_show_error()` to display Validation Errors.
- You can set the locale to :php:func:`route_to()` if you pass a locale value as the last parameter.
Expand Down