Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/html5 #743

Closed
wants to merge 3 commits into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions system/helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,54 @@ function form_input_range($data = '', $min = 0, $max = 0, $step = 0, $value = ''

// ------------------------------------------------------------------------

/**
* Datalist
*
* Create an html5 datalist.
*
* @access public
* @param array $options
* @param mixed $attributes
*/
if ( ! function_exists('form_datalist')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curly braces need to be placed on separate lines, like you've done with the if()s.

function form_datalist($options, $id, $attributes = '') {
// If an array wasn't submitted there's nothing to do...
if ( ! is_array($options))
{
return $options;
}

// Were any other attributes submitted? If so generate a string
if (is_array($attributes))
{
$atts = '';
foreach ($attributes as $key => $val)
{
$atts .= ' ' . $key . '="' . $val . '"';
}
$attributes = $atts;
}
elseif (is_string($attributes) AND strlen($attributes) > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AND -> &&

{
$attributes = ' '. $attributes;
}

$out = "<datalist id=\"$id\"$attributes>\n";
foreach ($options as $key => $val)
{
$out .= " ";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those 4 lines should be just one:

$out .= ' <option>'.$val."</option>\n";

$out .= "<option>";
$out .= $val;
$out .= "</option>\n";
}
$out .= "</datalist>\n";

return $out;
}
}

// ------------------------------------------------------------------------

/**
* Password Field
*
Expand Down
32 changes: 32 additions & 0 deletions system/helpers/html_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,38 @@ function nbs($num = 1)
}
}

// ------------------------------------------------------------------------

/**
* Generates an HTML progress element
*
* @access public
* @param mixed value progress value or an array of attributes
* @param string content
* @param integer min
* @param integer max
* @param string extra
* @return string
*/
if ( ! function_exists('progress'))
{
function progress($value='', $content='', $extra='')
{
if (is_array($value))
{
foreach ($value as $key=>$value)
{
$data .= $key.'="'.$value.'" ';
}
}
else {
$data = 'value="'.$value.'"';
}
if ($extra) $extra = ' '.trim($extra);
return '<progress '.trim($data).$extra.'>'.$content.'</progress>';
}
}


/* End of file html_helper.php */
/* Location: ./system/helpers/html_helper.php */
10 changes: 10 additions & 0 deletions user_guide/helpers/form_helper.html
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ <h2>form_textarea()</h2>
example, you will instead specify "rows" and "cols".</p>


<h2>form_datalist()</h2>

<p>Let's you create an html5 datalist element. The first parameter will contain an array of options, the second parameter will be the id attribute,
and the third will be an optional string or associative array of other attributes</p>

<code>$options = array('value 1', 'value 2');<br />
echo form_datalist($options, 'mylist');
</code>


<h2>form_dropdown()</h2>

<p>Lets you create a standard drop-down field. The first parameter will contain the name of the field,
Expand Down
18 changes: 18 additions & 0 deletions user_guide/helpers/html_helper.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,24 @@ <h2><a name="doctype"></a>doctype()</h2>
</table>


<h2><a name="progress"></a>progress()</h2>
<p>Lets your create an html5 progress element.</p>
<code>
&lt;progress value="25"&gt;25%&lt;/progress&gt;
</code>
<p>The tag has 3 parameters:</p>
<code>
progress(<var>value of the progress meter</var>, <var>the content</var>, <var>extra attributes</var>);
</code>
<p>The first parameter is the value, or an array of attributes. The second is the content data, and the third parameter can contain a string of attributes you would like added to the progress bar.</p>
<code>
echo progress(50, '50%', 'max="100"');
</code>
<p>Would produce: &lt;progress value="50" max="100"&gt;50%&lt;/progress&gt;</p>
<code>
echo progress(array('value'=>'0.75', 'step'=>'0.1', 'min'=>'0', 'max'=>1), 'we are at 75%');
</code>
<p>Would produce: &lt;progress value="75" step="0.1" min="0" max="1"&gt;we are at 75%&lt;/progress&gt;</p>


</div>
Expand Down