Welcome Guest, Not a member yet? Register   Sign In
Lib or helper for Bootstrap forms
#1

is there any lib or helper to create forms with bootstrap wich do:
- works with ci
- collect all nessesary js and css per bootstrap form element by its self and put to html output
- no div tags
- allows rules

Thanks
Gregor
Reply
#2

Best place to look would be here:

THE BIG BADASS LIST OF 318 USEFUL TWITTER BOOTSTRAP RESOURCES
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

it is not what i'm looking for.
When you make views with BT in CI you have to take care with all the <div> tags.
Is there a helper or Lib which will do the job?

like this --> https://github.com/wallter/codeigniter_b...rm_builder

(was not able to get it working in CI 3)
Reply
#4

(10-22-2016, 06:08 AM)gregor4711 Wrote: it is not what i'm looking for.
When you make views with BT in CI you have to take care with all the <div> tags.
Is there a helper or Lib which will do the job?

like this --> https://github.com/wallter/codeigniter_b...rm_builder

(was not able to get it working in CI 3)

I haven't tried it specifically in CI3 but this code snippet can go in MY_form_helper.php and I believe it is what you are looking for.

Bob
Ignition Go

PHP Code:
<?php
/**
 * Helper class to handle form-related actions
 */

// Shortcut function for validate form
// [Optional] set "form_url" for location of the form page
// [Optional] set "rule_set" for name of rule sets in config/form_validation.php (if empty, CodeIgniter will detect as "controller/method" pattern, e.g. "account/update")
function validate_form($form_url ''$rule_set '')
{
    
$CI =& get_instance();
    
$CI->load->library('form_validation');
    if ( 
$CI->form_validation->run($rule_set) == FALSE )
    {
        if ( 
validation_errors() )
        {
            
// save error messages to flashdata
            
set_alert('danger'validation_errors());
            
// save all fields to flashdata for repopulating
            // note: set_value() will not work upon redirection
            
$CI->session->set_flashdata('form_fields'$CI->input->post());
            
// refresh or jump page to show error messagees
            
$url = empty($form_url) ? current_url() : $form_url;
            
redirect($url);
            exit();
        }
        
        
// display form
        
return FALSE;
    }
    else
    {
        
// success
        
return TRUE;
    }
}

// Text fields
function form_group_input($name$value ''$label ''$placeholder ''$required FALSE)
{
    
// get previous form values from flashdata (e.g. when there is error via validate_form() function)
    
$CI =& get_instance();
    
$form_fields $CI->session->flashdata('form_fields');
    
$label = empty($label) ? humanize($name) : $label;
    
$placeholder = empty($placeholder) ? $label $placeholder;
    
$value = empty($value) ? $form_fields[$name] : $value;
    
$type = ($name=='email') ? 'email' 'text';
    
$required $required 'required' '';
    return 
"<div class='form-group'>
        <label for='
$name'>$label</label>
        <input type='
$type' placeholder='$placeholder' id='$name' name='$name' class='form-control' value='$value$required>
    </div>"
;
}

// Password fields
function form_group_password($name 'password'$placeholder '')
{
    
$label humanize($name);
    
$placeholder = empty($placeholder) ? humanize($name) : $placeholder;
    
    return 
"<div class='form-group'>
        <div class='pi-input-with-icon'>
            <label for='
$name'>$label</label>
            <input type='password' placeholder='
$placeholder' id='$name' name='$name' class='form-control'>
        </div>
    </div>"
;
}

// Checkbox
function form_group_checkbox($name$label$checked FALSE)
{
    
$checked = empty($checked) ? '' 'checked';
    return 
"<div class='form-group'>".form_checkbox($name$label$checked)."</div>";
}

// Checkbox (override)
function form_checkbox($name$label$checked FALSE)
{
    
$checked = empty($checked) ? '' 'checked';
    return 
"<div class='checkbox'>
        <label><input type='checkbox' name='
$name$checked>$label</label>
    </div>"
;
}

// Disabled text fields
function form_group_input_disabled($label$value)
{
    return 
"<div class='form-group'>
        <label>
$label</label>
        <input type='text' class='form-control' value='
$value' disabled>
    </div>"
;
}

// Hyperlink
function form_group_link($label$url)
{
    
$href = empty($url) ? '#' site_url($url);
    return 
"<div class='form-group'><a href='$href'>$label</a></div>";

Reply




Theme © iAndrew 2016 - Forum software by © MyBB