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 - 03-18-2010

[eluser]mahrizal[/eluser]
I just can say : 'great...!'


Form Generation Library - El Forum - 03-23-2010

[eluser]john36122340[/eluser]
Hodwy guys,

I just started playing with the form library and can't get the select to work properly, I'm using the code straight from the demos: http://frankmichel.de/formgenlib/user_guide/elements/select.html

Code:
$sample_array = array(
            1 => 'One',
            2 => 'Two',
            3 => 'Three'
);

$this->form
    ->text('Your Name', 'name', 'required')
    ->select('single', $sample_array, 'Single Select', 2)
    ->submit();

$data['sample_form'] = $this->form->get();

$this->load->view('main_view', $data);

but I get this in the html markup:

Code:
<label for="single" class="label">Single Select</label>
<label for="single[]">id="single"</label>
<select name="single[]">
    <option value="1">One</option>
    <option value="2" selected="selected">Two</option>
    <option value="3">Three</option>
</select>

I am not sure if it has something to do with the config options so I uploaded a copy here: http://pastebin.com/symAhw8g

The code is generating 2 labels instead of 1, but even if I leave the label param blank
Code:
->select('single', $sample_array, '', 2)
, the ID attribute is still being put in the wrong place:

Code:
<label for="single[]">id="single"</label><select name="single[]">

Is this a bug or am I doing something wrong, really appreciate any help, being fighting with this for a couple of hours.

Thanks,

John


Form Generation Library - El Forum - 03-24-2010

[eluser]hugle[/eluser]
Hello,

have you downloaded the last version? strange, because I have just copy pasted your code, and all works fine.

Is is a Windows hosting? or maybe on localhost?


Form Generation Library - El Forum - 03-24-2010

[eluser]john36122340[/eluser]
Thanks for the reply hugle,

Really strange, did you run it with the config file I uploaded to pastebin?

I'm gonna try again, but TBH I don't really know what else to try...


Form Generation Library - El Forum - 03-25-2010

[eluser]maicobreako[/eluser]
I wanted to use a charcount.js library to limit the characters and provide a real time count for a textarea. I found this http://www.codefromjames.com/wordpress/?p=15 library for a previous non-formgen project. It worked great. However it requires a maxlength attribute be added to the textarea element. This is what I have just tested with a formgen project and it seems to work so far:

In application/libraries/Form.php (version 1.0.1), I made the following changes:

Line 100, I appended maxlength to the attributes array
Code:
'textarea' => 'cols|rows|accesskey|disabled|name|onblur|onchange|onfocus|onselect|readonly|tabindex|value|maxlength',

Line 1123 from
Code:
function textarea($nameid, $label='', $rules='', $value='', $atts=array())
To
Code:
function textarea($nameid, $label='', $rules='', $value='', $maxlength, $atts=array())
EDIT: After looking at it, $maxlength should be added after $atts=array(), so as not to change the common sequence. /EDIT

And added at line 1132
Code:
$info['maxlength'] = $maxlength; // Added 03/25/10 Tim S.

In the application, I do something like this
Code:
->textarea('comments', 'Comments', 'trim', "some text for testing", 500)

The generated source looks like this
Code:
&lt;textarea name="comments" cols="40" rows="10" id="comments" maxlength="500" style="margin-top:10px" &gt;some text for testing&lt;/textarea&gt;

Maybe this will be useful to others, or maybe some can suggest a better way. I understand that jquery and others also rely on maxlength, so maybe Frank can incorporate this attribute into a future version of his library.

BTW, a forum search did not produce any info on this. It would be nice if we could search individual threads. This one is 50 pages and is rather daunting to wade through to try to find something specific.


Form Generation Library - El Forum - 03-25-2010

[eluser]maicobreako[/eluser]
charcount.js also utilizes a lengthcut function which stops a user from proceeding beyond max. I added that attribute same as in the above post.

For example:
Code:
function textarea($nameid, $label='', $rules='', $value='', $atts=array(), $maxlength, $lengthcut)



Form Generation Library - El Forum - 03-26-2010

[eluser]James V[/eluser]
Edit- figured out what I have to do here.


Form Generation Library - El Forum - 03-28-2010

[eluser]hugle[/eluser]
[quote author="john36122340" date="1269463439"]Thanks for the reply hugle,

Really strange, did you run it with the config file I uploaded to pastebin?

I'm gonna try again, but TBH I don't really know what else to try...[/quote]

really strange. well I didn't use the config from pastebin, since if you used the default config file, this is not necessary....

your problem still persists?
what version of php do you have, btw?


Form Generation Library - El Forum - 03-28-2010

[eluser]James V[/eluser]
Possible bug w/ v101: Checkbox() is adding [] to the 'name' attribute.


Form Generation Library - El Forum - 03-28-2010

[eluser]hugle[/eluser]
[quote author="James V" date="1269828438"]Possible bug w/ v101: Checkbox() is adding [] to the 'name' attribute.[/quote]

hello
it is normal behaviour. sine checkboxes and listboxes always generate array.

so if you are sure that you always must have 1 chekbox checked, you just get that value by:
$post['name'][0];

good luck