Welcome Guest, Not a member yet? Register   Sign In
Validation v/s Form_Validation
#10

[eluser]LuckyFella73[/eluser]
[quote author="Yash" date="1251385063"]@luckyfella73
You are setting 2 times same value
[/quote]

Where do set the same value?

I just posted a bit code where the controller set the
initial value comming from database. After submitting
your form the "value-parameter" of your form element
has to be set using the post data.

In your controller/ edit function you need something like that:
Code:
<?php

# Controller - very simplified ..

function edit()
{
    if ( isset($_POST['form']) AND $_POST['form'] == 'form_edit' ) // the form has beend send
    {
        $data['title'] = $this->input->post('title');
        $data['date'] = $this->input->post('date');
        $data['text'] =$this->input->post('text');

        $this->form_validation->set_rules('title', 'Title', 'trim');
        $this->form_validation->set_rules('date', 'Date', 'trim');
        $this->form_validation->set_rules('text', 'Text', 'trim');

        if ($this->form_validation->run() == FALSE)
        {
            // in case validation fails, set values of form elements by using the POST values
            $this->load->view('news/view_news_edit.php', $data); // dummy filenames
        }
        else
        {
            // do your db stuff

            // call success page or whatever
        }
    }
    else // set initioal values from db:
    {
        # your query here

        if ($query->num_rows() > 0)
        {
            foreach ($query->result() as $row)
            {
                # whatever you want to edit from your db ..
                $data['title'] = $row->title;
                $data['date'] = $row->date;
                $data['text'] = $row->text;
            }
        }
        
        $this->load->view('news/view_news_edit.php', $data);
    }
}
?>

There are two parts in the code that set a form value but thats the
way you have to go if you want to edit data from db using a form because
the source of the values are different.

Sorry if I get you wrong completely


Messages In This Thread
Validation v/s Form_Validation - by El Forum - 08-21-2009, 03:40 AM
Validation v/s Form_Validation - by El Forum - 08-27-2009, 01:02 AM
Validation v/s Form_Validation - by El Forum - 08-27-2009, 01:17 AM
Validation v/s Form_Validation - by El Forum - 08-27-2009, 02:20 AM
Validation v/s Form_Validation - by El Forum - 08-27-2009, 02:40 AM
Validation v/s Form_Validation - by El Forum - 08-27-2009, 03:15 AM
Validation v/s Form_Validation - by El Forum - 08-27-2009, 03:27 AM
Validation v/s Form_Validation - by El Forum - 08-27-2009, 03:52 AM
Validation v/s Form_Validation - by El Forum - 08-27-2009, 03:57 AM
Validation v/s Form_Validation - by El Forum - 08-27-2009, 04:47 AM
Validation v/s Form_Validation - by El Forum - 08-27-2009, 05:52 AM
Validation v/s Form_Validation - by El Forum - 11-03-2009, 09:38 PM



Theme © iAndrew 2016 - Forum software by © MyBB