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 - 05-17-2010

[eluser]hardik[/eluser]
@BaRzO
thanks for the library.


Form Generation Library - El Forum - 05-27-2010

[eluser]seanloving[/eluser]
You never need to call ->validate() because ->get() calls it automatically.

is this correct?

SL


Form Generation Library - El Forum - 07-05-2010

[eluser]Maglok[/eluser]
@poster: Correct.

Question myself: I have an array like this:

Code:
$config['systeem'] = array(    'something' => 'Something old',
                            'new' => 'Something new',
                            'blue' => 'Something blue'
                            );

Fictional values. I then use the library like so:
Code:
->select('categorie', $categorieen, 'Categorie', '', 'required')

Which generates this:
Code:
<label for="categorie" class="right required">Categorie*</label><select name="categorie[]" id="categorie">
<option value="0" selected="selected">Something old</option>
<option value="1">Something new</option>
<option value="2">Something blue</option>
</select>

Basically, why are the values not the ones I assigned? If I "$bericht['categorie'] = $input['categorie'][0];" then I get 0, 1 or 2 and not 'something', 'old' or 'blue'.


Form Generation Library - El Forum - 07-05-2010

[eluser]macigniter[/eluser]
[quote author="Maglok" date="1278336232"]

Code:
$config['systeem'] = array(    'something' => 'Something old',
                            'new' => 'Something new',
                            'blue' => 'Something blue'
                            );

Fictional values. I then use the library like so:
Code:
->select('categorie', $categorieen, 'Categorie', '', 'required')
[/quote]

You're not assigning $config['systeem'], you're assigning $categorieen. Or is that just a typo in your example?


Form Generation Library - El Forum - 07-05-2010

[eluser]Maglok[/eluser]
Í forgot to list another step I do:

Code:
$categorieen = $this->config->item('systeem');
        $categorieen['overig'] = "Overig";

Since I add another option.


Form Generation Library - El Forum - 07-05-2010

[eluser]BaRzO[/eluser]
@macigniter nice too hear from you Wink

Is it right fix split fix


Form Generation Library - El Forum - 07-05-2010

[eluser]macigniter[/eluser]
[quote author="Mustafa Kahraman" date="1278338156"]@macigniter nice too hear from you Wink

Is it right fix split fix[/quote]

Hi there! Is that a Form Generation Library issue or a general question for your code since split() isn't used in the latest version of the library...

In certain cases you can substitue split() with explode(), but not if you use a regular expression pattern. But you're fine if you're just using it to do something like explode(';', $text);


Form Generation Library - El Forum - 07-05-2010

[eluser]macigniter[/eluser]
[quote author="Maglok" date="1278337729"]Í forgot to list another step I do:

Code:
$categorieen = $this->config->item('systeem');
        $categorieen['overig'] = "Overig";

Since I add another option.[/quote]

I just tested this and it worked perfectly with the demo. There must be an error in your code somewhere... Undecided


Form Generation Library - El Forum - 07-05-2010

[eluser]Maglok[/eluser]
Alright here we go, more complete:

Code:
/*****
     * Maak een nieuws bericht aan
     */
    function add() {
        $data = $this->permissions();
        if (!isset($data['moderator']) && !isset($data['administrator'])) {
            $this->session->set_flashdata('bericht', 'Je hebt geen rechten om nieuws berichten te posten');
            redirect('nieuws', 'location');
        }

        $this->load->library('form');
        $data['pagina_titel'] = 'Nieuw bericht';
        $data['header'] = 'nieuws';
        $categorieen = $this->config->item('systeem');
        $categorieen['overig'] = "Overig";
        sort($categorieen);

        $this->form
            ->open()
            ->text('titel', 'Titel', 'required|trim|max_length[50]|xss_clean')
            ->select('categorie', $categorieen, 'Categorie', '', 'required')
            ->indent(150)
            ->checkbox('community', TRUE, 'Publiceer naar de community feed', FALSE, 'trim|xss_clean')
            ->indent(0)
            ->textarea('inhoud', 'Inhoud', '')
            ->add_class('editor')
            ->submit('Opslaan')
            ->reset('Leegmaken')
            ->margin(10);

        $data['form'] = $this->form->get();
        
        if ($this->form->valid) {
            $input = $this->form->get_post();
            $bericht['titel'] = $input['titel'];
            $bericht['categorie'] = $input['categorie'][0];
            $bericht['inhoud'] = $input['inhoud'];
            $bericht['auteur_id'] = $this->phpbb_library->getUserInfo('user_id');
            $bericht['date_created'] = date('Y-m-d H:i:s');

            if($input['community'][0]) {
                $bericht['community'] = TRUE;
            } else {
                $bericht['community'] = FALSE;
            }

            $this->model_nieuws->add_nieuws($bericht);
            if ($bericht['community'] == TRUE) {
                $this->generateRss(TRUE);
            }
            $this->generateRss();
            $this->session->set_flashdata('bericht', 'Nieuws bericht toegevoegd.');
            redirect('nieuws');    
        } else {
            $data['errors'] = $this->form->errors;
        }
        $this->load->view('nieuws/add', $data);
    }

I honestly tried, but it will not return the proper key value, but instead generate with 0,1,2


Form Generation Library - El Forum - 07-05-2010

[eluser]macigniter[/eluser]
Looks like this is related to the sort() function which will most probably re-index your values with numeric keys...