Welcome Guest, Not a member yet? Register   Sign In
Multiselect Dropdown validation [Solved- Me Stupid :) ]
#21

[eluser]xpix[/eluser]
I still can't see the error

Here is the view:
Code:
<?
    echo form_open($this->uri->slash_segment(1) . 'advisers/add');
    ?>
    
    <div class="formrow">&lt;?= form_label('Name: ', 'name') . form_input('name');?&gt;</div>
    <div class="formrow">&lt;?= form_label('Email: ', 'email') . form_input('email');?&gt;</div>
    <div class="formrow">&lt;?= form_label('Password', 'pass') . form_input('pass');?&gt;</div>
    <div class="formrow">&lt;?= form_label('Programs: ', 'programs') . form_dropdown('programs[]',$programs_list,'','size="5" multiple="multiple"');?&gt;&nbsp;&nbsp; <em>Select Multiple</em></div>
    <div class="formrowsubmit">&lt;?= form_submit('submit', 'Add');?&gt;</div>
    
    &lt;?
    echo form_close();
    ?&gt;


and the controller:
Code:
}else if($action == 'add'){  ///ADDDDDDDDDD
            
            $this->form_validation->set_rules('name', 'Name', 'required|trim|xss_clean');
            $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
            $this->form_validation->set_rules('pass', 'Password', 'trim|required|min_length[6]');
            $this->form_validation->set_rules('programs', 'Programs', 'required|trim|xss_clean');
            
            //$data['debug'] = $this->input->post('programs');
            
            if ($this->form_validation->run() == FALSE){
            
            }else{
            
                $result = $this->Adviser->add($this->input->post('name'), $this->input->post('email'), $this->input->post('pass'));
                
                if(!$result){
                    $data['errors'] = "<p>An error has occured!</p>";
                }else{
                    $lastAdviserId = $this->db->insert_id();
                    
                    $data['messages'] = "<p>Success!</p>" . $result;
                    
                    //put programs in DB
                    if($this->input->post('programs')){
                        foreach($this->input->post('programs') as $programId){
                            $this->db->insert('jb_adviser2programs', array( 'adviserId' => $lastAdviserId , 'programId' =>  $programId));
                        }
                    }
                }
            }
            
        }else if($action == 'delete'){


The other 3 fields get validated but the "programs"

Maybe I am missing something

Thx
#22

[eluser]TheFuzzy0ne[/eluser]
Are you saying that you're not getting an error using the demo app I provided? If that works, but your code doesn't then it's clear that something is not right somewhere in your code.
#23

[eluser]xpix[/eluser]
Here are the logs
Code:
DEBUG - 2009-05-24 14:38:52 --&gt; Config Class Initialized
DEBUG - 2009-05-24 14:38:52 --&gt; Hooks Class Initialized
DEBUG - 2009-05-24 14:38:52 --&gt; URI Class Initialized
DEBUG - 2009-05-24 14:38:52 --&gt; Router Class Initialized
DEBUG - 2009-05-24 14:38:52 --&gt; Output Class Initialized
DEBUG - 2009-05-24 14:38:52 --&gt; Input Class Initialized
DEBUG - 2009-05-24 14:38:52 --&gt; Global POST and COOKIE data sanitized
DEBUG - 2009-05-24 14:38:52 --&gt; Language Class Initialized
DEBUG - 2009-05-24 14:38:52 --&gt; Loader Class Initialized
DEBUG - 2009-05-24 14:38:52 --&gt; Helper loaded: url_helper
DEBUG - 2009-05-24 14:38:52 --&gt; Helper loaded: form_helper
DEBUG - 2009-05-24 14:38:52 --&gt; Helper loaded: security_helper
DEBUG - 2009-05-24 14:38:52 --&gt; Helper loaded: html_helper
DEBUG - 2009-05-24 14:38:52 --&gt; Database Driver Class Initialized
DEBUG - 2009-05-24 14:38:52 --&gt; Form Validation Class Initialized
DEBUG - 2009-05-24 14:38:52 --&gt; Session Class Initialized
DEBUG - 2009-05-24 14:38:52 --&gt; Helper loaded: string_helper
DEBUG - 2009-05-24 14:38:52 --&gt; Session routines successfully run
DEBUG - 2009-05-24 14:38:52 --&gt; Table Class Initialized
DEBUG - 2009-05-24 14:38:52 --&gt; Controller Class Initialized
DEBUG - 2009-05-24 14:38:52 --&gt; Model Class Initialized
DEBUG - 2009-05-24 14:38:52 --&gt; File loaded: /var/www/websites/ccccc/jobs-staging/system/application/views/admin-header.php
DEBUG - 2009-05-24 14:38:52 --&gt; File loaded: /var/www/websites/ccccc/jobs-staging/system/application/views/admin-menu.php
DEBUG - 2009-05-24 14:38:52 --&gt; File loaded: /var/www/websites/ccccc/jobs-staging/system/application/views/admin-programs.php
DEBUG - 2009-05-24 14:38:52 --&gt; File loaded: /var/www/websites/ccccc/jobs-staging/system/application/views/admin-footer.php
DEBUG - 2009-05-24 14:38:52 --&gt; Language file loaded: language/english/profiler_lang.php
DEBUG - 2009-05-24 14:38:52 --&gt; Helper loaded: text_helper
DEBUG - 2009-05-24 14:38:52 --&gt; Final output sent to browser
DEBUG - 2009-05-24 14:38:52 --&gt; Total execution time: 0.0593

no errors
#24

[eluser]xpix[/eluser]
[quote author="TheFuzzy0ne" date="1243291698"]Are you saying that you're not getting an error using the demo app I provided? If that works, but your code doesn't then it's clear that something is not right somewhere in your code.[/quote]

I get this

Parse error: parse error, unexpected $ in /var/www/websites/ccccc/jobs-staging/system/application/controllers/test.php on line 57
#25

[eluser]xpix[/eluser]
[quote author="xpix" date="1243291977"][quote author="TheFuzzy0ne" date="1243291698"]Are you saying that you're not getting an error using the demo app I provided? If that works, but your code doesn't then it's clear that something is not right somewhere in your code.[/quote]

I get this

Parse error: parse error, unexpected $ in /var/www/websites/ccccc/jobs-staging/system/application/controllers/test.php on line 57[/quote]


I got it to work. It was a spacing issue in the multiline assignment.

You're code works but I still cannot see the problem in my code.

Thx for you help
#26

[eluser]TheFuzzy0ne[/eluser]
Code:
$this->form_validation->set_rules('programs', 'Programs', 'required|trim|xss_clean');

Should be:

Code:
$this->form_validation->set_rules('programs[]', 'Programs', 'required|trim|xss_clean');
#27

[eluser]xpix[/eluser]
STUPID STUPID STUPID!!!

I forgot to add the error to this line


$error_output = form_error('name') . form_error('email') . form_error('pass') . form_error('programs') . $errors;
:coolgrin:

I changed the line to

$error_output = validation_errors() . $errors;

This way I catch all the errors.

Thx for your help
#28

[eluser]TheFuzzy0ne[/eluser]
You can go one better and do this:

Code:
$error_output = validation_errors() . $errors;




Theme © iAndrew 2016 - Forum software by © MyBB