Welcome Guest, Not a member yet? Register   Sign In
$this->validation->set_select Will not select
#1

[eluser]Lexperts[/eluser]
Hi,

I try too select the manufacturer_id on my update page. But it is not working. When a want to get the values of others. Then it works fine (title, size, price).

Code:
$this->validation->title         = quotes_to_entities($record->title);
$this->validation->manufacturer_id    = $record->manufacturer_id;
$this->validation->size         = quotes_to_entities($record->size); <-- There is a value, but it will not be selected in my view
$this->validation->price         = $this->cart->format_number($record->price);

This is my controller:
Code:
function update(){
        
        $data['page_title']    = 'Artikel updaten';
        $data['meta']     = array(
                array('name' => 'description', 'content' => 'Mailgroepen'),
                array('name' => 'keywords', 'content' => 'mailen, nieuws, mailsysteem'),
                array('name' => 'robots', 'content' => 'no-cache'),
                array('name' => 'Content-type', 'content' => 'text/html; charset=utf-8', 'type' => 'equiv')
        );
          
           $query                     = $this->manufacturer_model->get_records();
        $data['manufacturers']     = $query;
          
           $product_id = $this->uri->segment(3, FALSE);
        
        if(!$product_id){
            redirect('product');
        }
        
        if($query = $this->product_model->get_record($product_id)){
            $record = $query;            
        } else {
            redirect('product');
        }
        
        $this->_set_fields();
        $this->_set_rules();
        
        $data['action']         = site_url('product/update/' . $product_id);
        $data['submit_value']    = 'Opslaan';
                
        $this->validation->title             = quotes_to_entities($record->title);
        $this->validation->manufacturer_id    = $record->manufacturer_id;
        $this->validation->size             = quotes_to_entities($record->size);
        $this->validation->price             = $this->cart->format_number($record->price);
                
        if ($this->validation->run() == FALSE){
            $data['view']     = 'product/form';
        } else {
            $data = array(
                    'manufacturer_id'     => $this->input->post('manufacturer_id', TRUE),
                    'title'             => $this->input->post('title', TRUE),
                    'size'                 => $this->input->post('size', TRUE),
                    'price'                 => $this->input->post('price', TRUE)
            );
        
            $this->product_model->update_record($data, $product_id);
        
            $this->session->set_flashdata('messages', 'Het artikel is succesvol geupdate.');
            $this->session->set_flashdata('messages_css', 'succes');
            redirect('product');
        }
        
        $this->load->view('template', $data);
        
    }
function _set_fields(){
        $fields['title']             = 'title';
        $fields['manufacturer_id']     = 'manufacturer_id';
        $fields['size']             = 'size';
        $fields['price']             = 'price';
        $this->validation->set_fields($fields);
    }
    
    function _set_rules(){
        $rules['title']             = 'trim|required';
        $rules['manufacturer_id']     = 'callback_manufacturer_check';
        $rules['size']                 = 'trim|required';
        $rules['price']             = 'trim|required|numeric';
        $this->validation->set_rules($rules);
        $this->validation->set_error_delimiters('<div class="notification error">', '</div><div class="space"></div>');
    }
    
    function manufacturer_check(){
        $this->validation->set_message('manufacturer_check', 'Kies een merk');
        return $this->manufacturer_model->check_record($this->input->post('manufacturer_id', TRUE));
    }

This is my view

Code:
&lt;?php echo $this->validation->error_string; ?&gt;
<div class="form">
&lt;?=form_open($action)?&gt;
    <fieldset>
        <legend>Algemene gegevens</legend>
            <div class="row"><label>Artikel naam:</label>
            &lt;input type="text" name="title" value="&lt;?php echo $this-&gt;validation->title; ?&gt;" /></div>
            <div class="row"><label>Merk:</label>
                <select name="manufacturer_id">
                    <option value="FALSE">Kies een merk</option>
                    &lt;?php foreach($manufacturers as $manufacturer):?&gt;
                        <option value="&lt;?=$manufacturer->manufacturer_id?&gt;" &lt;?php echo $this->validation->set_select('manufacturer_id', $manufacturer->manufacturer_id);?&gt;>&lt;?=quotes_to_entities($manufacturer->title)?&gt;</option>
                    &lt;?php endforeach; ?&gt;
                </select>
            </div>
            <div class="row"><label>Maat:</label>
            &lt;input type="text" name="size" value="&lt;?php echo $this-&gt;validation->size; ?&gt;" /></div>
            <div class="row"><label>Prijs:</label>
            &lt;input type="text" name="price" value="&lt;?php echo $this-&gt;validation->price; ?&gt;" /></div>
    </fieldset>
    <div class="space"></div>
    <div class="space"></div>
    &lt;input class="form-submit" type="submit" value="&lt;?=$submit_value?&gt;" /&gt;
&lt;/form&gt;

Thanks in advance!

Lex
#2

[eluser]Buso[/eluser]
Validation class has been deprecated, so I don't know much about this

Why not try with Form_validation class? http://codeignitor.com/user_guide/librar...ation.html
#3

[eluser]Lexperts[/eluser]
Why is that?
#4

[eluser]Lexperts[/eluser]
Nobody?
#5

[eluser]Buso[/eluser]
Well I don't know the reasons that ellislab guys had to deprecate it, what I know is that it has been like that since before I even started with codeIgniter, so I don't know why you are using it.
And it has been completely removed from CI 2.0.

I never used it, so I don't know.
#6

[eluser]Lexperts[/eluser]
Thanks for your reply. I gone check the Form_validation class.




Theme © iAndrew 2016 - Forum software by © MyBB