From 707d0e0f1e0ea922fbe38d8b43f1fb4e2ea001e5 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 18 Mar 2008 11:50:00 +0000 Subject: added form_button to form helper --- system/helpers/form_helper.php | 27 ++++++++++++++++++++ user_guide/changelog.html | 1 + user_guide/helpers/form_helper.html | 49 +++++++++++++++++++++++++++++++------ 3 files changed, 69 insertions(+), 8 deletions(-) diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 7c3b16ff1..db41cb5cd 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -386,6 +386,33 @@ if (! function_exists('form_reset')) // ------------------------------------------------------------------------ +/** + * Form Button + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +if (! function_exists('form_button')) +{ + function form_button($data = '', $content = '', $extra = '') + { + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'submit'); + + if ( is_array($data) AND isset($data['content'])) + { + $content = $data['content']; + unset($data['content']); // content is not an attribute + } + + return "\n"; + } +} + +// ------------------------------------------------------------------------ + /** * Form Label Tag * diff --git a/user_guide/changelog.html b/user_guide/changelog.html index b8bbb330e..7ba6c3e7b 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -69,6 +69,7 @@ Change Log
  • Helpers diff --git a/user_guide/helpers/form_helper.html b/user_guide/helpers/form_helper.html index 95041e562..fa33e6a48 100644 --- a/user_guide/helpers/form_helper.html +++ b/user_guide/helpers/form_helper.html @@ -288,12 +288,12 @@ echo fieldset_close($string);

    Similar to the other form functions in this helper, you can also pass an array of attributes to the function:

    $data = array(
    -              'name'        => 'newsletter',
    -              'id'          => 'newsletter',
    -              'value'       => 'accept',
    -              'checked'     => TRUE,
    -              'style'       => 'margin:10px',
    -            );
    +    'name'        => 'newsletter',
    +    'id'          => 'newsletter',
    +    'value'       => 'accept',
    +    'checked'     => TRUE,
    +    'style'       => 'margin:10px',
    +    );

    echo form_checkbox($data);

    @@ -331,8 +331,8 @@ fourth parameter:

    <label id="username">What is your Name</label>

    Similar to other functions, you can submit an associative array in the third parameter if you prefer to set additional attributes.

    $attributes = array(
    - 'class' => 'mycustomclass',
    - 'style' => 'color: #000;',
    +    'class' => 'mycustomclass',
    +    'style' => 'color: #000;',
    );
    echo form_label('What is your Name', 'username', $attributes);

    @@ -342,6 +342,39 @@ fourth parameter:

    Lets you generate a standard reset button. Use is identical to form_submit().

    +

    form_button()

    + +

    Lets you generate a standard button element. You can minimally pass the button name and content in the first and second parameter:

    + +echo form_button(’name’,’content’);
    +
    +// Would produce
    +<button name="name" type="submit">Content</button> +
    + +Or you can pass an associative array containing any data you wish your form to contain: + +$data = array(
    +    ‘name’ => ‘button’,
    +    ‘id’ => ‘button’,
    +    ‘value’ => ‘true’,
    +    ‘type’ => ‘reset’,
    +    ‘content’ => ‘Reset’
    +);
    +
    +echo form_button($data);
    +
    +// Would produce:
    +<button name="button" id="button" value="true" type="reset">Reset</button> +
    + +If you would like your form to contain some additional data, like JavaScript, you can pass it as a string in the third parameter: + +$js = ‘onClick="some_function()"’;

    +echo form_button(’mybutton’, ‘Click Me’, $js); +
    + +

    form_close()

    Produces a closing </form> tag. The only advantage to using this function is it permits you to pass data to it -- cgit v1.2.3-24-g4f1b