CodeIgniter Forums
Form Generation Library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Form Generation Library (/showthread.php?tid=16439)



Form Generation Library - El Forum - 07-06-2009

[eluser]got 2 doodle[/eluser]
an excerpt from the controller
Code:
$this->load->library('form');


        // define radiobuttons, checkboxes and select options
        $pre_post[] = array('1', 'Infrastructure - grounds clean up');

        $pre_post[] = array('2', 'Campground');
        $pre_post[] = array('4', 'Tickets / Box Office');
        $pre_post[] = array('8', 'Media / Promotions');
        $pre_post[] = array('16', 'Loader / Stage Crew');
        $v_license = 2;
       // $driver[] = array('2','unspecified');

        

        $avail[] = array('0|msg1', 'I am available to volunteer for just the festival weekend only.',
        "onmouseup=Effect.BlindUp('avail_message1' );Effect.BlindUp('avail_message2' );Effect.BlindDown('avail_message0');Effect.Shake('msg2');Effect.Shake('msg3'); return false;");
        
        $avail[] = array('1|msg2', 'I am available to volunteer the week leading up to and/or the week after the festival',
        "onmouseup=Effect.BlindUp('avail_message0' );Effect.BlindUp('avail_message2' );Effect.BlindDown('avail_message1'); return false;");
        $avail[] = array('2|msg3', 'I am available to volunteer the week leading up to and/or the week after the festival <br /><strong>AND</strong> the festival weekend',
        "onmouseup=Effect.BlindUp('avail_message0' );Effect.BlindUp('avail_message1' );Effect.BlindDown('avail_message2'); return false;");





$event_date='August 7, 2009';
$food_handler_desc="If you checked the food handler box.\n\nPlease provide some details about your training and experience.";
$qualification_desc="If you have other qualifications that you believe would be helpful\n\nPlease list them here.";
$form = new Form();
        $form
        ->config(1)

        ->open($this->prefix.'/form2/'.$user_id)

// identification
        ->config(2)
        ->fieldset('Availability')

        ->radiogroup('availability',$avail)
        ->br()
        ->html('<div class="info" id="avail_message0" style="display:none"><p>This might be a good time to point out.</p>
        <ul>
        <li>you can get a daypass for only 6 volunteer hours</li>
        <li>you can get a weekend pass for 12 volunteer hours</li>
        </ul>
        <p>If you can you might want to choose one of the other options so that you can volunteer your time before or after the event and you get to enjoy the festival during the weekend of the event.</div>')
       ->html('<div class="info" id="avail_message1" style="display:none"><p>Thanks, we really need volunteers like you to help us make this a great event. These are the tasks that we need people for before and after the event.</p>')
        ->checkgroup('prepost_a',$pre_post)
       ->html('<p>A volunteer manager will be contacting you for your time before and after the event.</p>')
       ->submit('Submit','pre_submit')
       ->html('</div>')
       ->html('<div class="info" id="avail_message2" style="display:none"><p>Fantastic! we really need volunteers like you to help us make this a great event.  In addition to the following tasks that we require before and after the event, all tasks that you qualify for will be shown to you on the next page.</p>')
       ->checkgroup('prepost_b',$pre_post)
      ->html('<p>A volunteer manager will be contacting you for your time before and after the event.</p></div>')



        ->fieldset('Food Handler')
etc.

config file
Code:
&lt;?php
// config set one
$nameasid[1] = TRUE;
$replace[1] = 'FALSE|TRUE|TRUE';
$break_after[1] = 'text|password|textarea|upload|select|button';
$label_pos[1] = 'before';
$label_req_class[1] = 'required';
$label_req_flag[1] = '<span style="color:yellow"> * </span>';
$error_open[1] = '<div style="color: #F00">- ';
$error_close[1] = '</div>';
$error_string_open[1] = '<div id="errors">';
$error_string_close[1] = '</div>';
$error_class[1] = 'error';
$error_inline[1] = TRUE;
$error_inline_open[1] = '';
$error_inline_close[1] = '';
$error_flag[1] = '<span style="color:yellow"> {error}</span>';
$globals[1] = array();
$message[1] ='Fields marked with <span style="color:yellow">*</span> are required.';
$defaults[1] = array(
    'label' => array(    // this applies to all labels
        'class' => 'left'
    ),
    'label|checkbox' => array(    // this only applies to labels of checkboxes
        'class' => 'check'
    ),
    'label|radio' => array(    // this only applies to labels of radios
        'class' => 'check'
    ),
    'text' => array(
        'onblur' => "document.getElementById('message')[removed] = ''"
    ),
    'password' => array(
        'onkeypress' => "this.style.borderColor='#666'"
    ),    
    'upload' => array(
        'upload_path' => 'uploads',
        'allowed_types' => 'pdf|doc|jpg|gif|png'
    ),
    'checkbox' => array(
        'class' => 'check'
    ),
    'radio' => array(
        'class' => 'check'
    ),
    'submit' => array(
        'class' => 'button'
    ),
    'reset' => array(
        'class' => 'button'
    ),
    // always define defaults for specific elements (below) after defaults by element type (above)
    'multiple' => array(
        'style' => 'height: 120px'
    )
);



Form Generation Library - El Forum - 07-06-2009

[eluser]macigniter[/eluser]
I wonder why your radiobutton and checkbox &lt;input&gt;&lt;label&gt;'s are followed by a &lt;br /&gt;. Did you modify the library?


Form Generation Library - El Forum - 07-07-2009

[eluser]got 2 doodle[/eluser]
I modified the config file to have two different configs.

Code:
// config set two
$nameasid[2] = TRUE;
$replace[2] = 'FALSE|TRUE|TRUE';
$break_after[2] = 'text|password|textarea|upload|select|button|radio|checkbox';
$label_pos[2] = 'before';
$label_req_class[2] = 'required';
$label_req_flag[2] = '<span style="color:yellow"> * </span>';
..etc..

in my controller
Code:
$form = new Form();
        $form
        ->config(1)

        ->open($this->prefix.'/form2/'.$user_id)

// identification
        ->config(2)
        ->fieldset('Availability')

        ->radiogroup('availability',$avail)
        ->br()

A second look at my code and I don't think the ->config(1) is necessary but I posted it un-edited.

The only change to the lib was your new posted code, please see this post

doodle


Form Generation Library - El Forum - 07-07-2009

[eluser]adamp1[/eluser]
This looks like a nice library. One thing I would suggest is first that is one massive file with multiple classes in, why not separate them out into their own files. Another thing is there is a lot of clever code to handle creating the form and then process it, but how often do you update the forms on your website. I didn't get to look through it all but I know if its not going to change very often why not cache the form or save it to ease on the loading of it. Doesn't waste resources that way.


Form Generation Library - El Forum - 07-07-2009

[eluser][x26]VOLAND[/eluser]
1)Trying to create a button:
Code:
->button('<em>Click me!</em>', 'button', 'button', 'onclick="alert(\'Hello World!\')"');
An error appears:
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined variable: el
Filename: libraries/Form.php
Line Number: 581

2)
Code:
->submit('Enter')
->hidden('pwd', 'xyz123huikj')
produces
Code:
&lt;input type="submit" name="submit" value="Enter" id="submit"/&gt;
&lt;input type="submit" name="submit" value="Enter" id="submit"/&gt;
What's the problem?


Form Generation Library - El Forum - 07-17-2009

[eluser]macigniter[/eluser]
[quote author="[x26]VOLAND" date="1247008356"]1)Trying to create a button:
Code:
->button('<em>Click me!</em>', 'button', 'button', 'onclick="alert(\'Hello World!\')"');
An error appears:
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined variable: el
Filename: libraries/Form.php
Line Number: 581

2)
Code:
->submit('Enter')
->hidden('pwd', 'xyz123huikj')
produces
Code:
&lt;input type="submit" name="submit" value="Enter" id="submit"/&gt;
&lt;input type="submit" name="submit" value="Enter" id="submit"/&gt;
What's the problem?[/quote]

Thanks for your post. I have already fixed the cause for your first problem.

Can you please provide some more info for me to solve the second one? I cannot reproduce the problem with the double submit field.


Form Generation Library - El Forum - 07-17-2009

[eluser]macigniter[/eluser]
[quote author="adamp1" date="1246995500"]This looks like a nice library. One thing I would suggest is first that is one massive file with multiple classes in, why not separate them out into their own files. Another thing is there is a lot of clever code to handle creating the form and then process it, but how often do you update the forms on your website. I didn't get to look through it all but I know if its not going to change very often why not cache the form or save it to ease on the loading of it. Doesn't waste resources that way.[/quote]

thanks. suggestions are always welcome! i generally prefer to have one file only instead of lots of files cluttered around. but you are welcome to suggest a better way of handling this. i appreciate every input!! also about the caching. i am not too familiar with it, so if you have suggestions or improvements, please pm me or post them here!


Form Generation Library - El Forum - 07-17-2009

[eluser]macigniter[/eluser]
[quote author="got 2 doodle" date="1246994206"]I modified the config file to have two different configs.

Code:
// config set two
$nameasid[2] = TRUE;
$replace[2] = 'FALSE|TRUE|TRUE';
$break_after[2] = 'text|password|textarea|upload|select|button|radio|checkbox';
$label_pos[2] = 'before';
$label_req_class[2] = 'required';
$label_req_flag[2] = '<span style="color:yellow"> * </span>';
..etc..
[/quote]

with this set-up in the config file every radiobutton and/or checkbox will be followed by a &lt;br /&gt;

the problem with IE8 (or my CSS ;-)) is that the breaks do not clear the float, so in order to make it work in IE8, too you need to add:

Code:
form br {
   clear: left;
}

hope that helped!!

i will look into this and see if that is something that should be added to the CSS by default. anyone who doesn't need it can always comment it out or delete it...

what do you guys think?


Form Generation Library - El Forum - 07-17-2009

[eluser]macigniter[/eluser]
@everybody

A new version with some minor fixes has just been uploaded. it gets rid of some more PHP notices. any suggestions, feedback, bug report or php notices? PLEASE send them to me!! :-)

I will also try to finally complete the user guide since I have a little time on my hand and no rush project going on right now. keep your fingers crossed ;-)


Form Generation Library - El Forum - 07-17-2009

[eluser]got 2 doodle[/eluser]
Thanks for the mods to the CSS

It worked fine in IE8 and doesn't seem to be broken in other browsers, although I haven't checked many.

Looking forward to the manual!

I will check out the new release :coolsmile:

doodle