Welcome Guest, Not a member yet? Register   Sign In
Edit, validate, re-edit issue using set_value with optional parameter
#21

[eluser]bretticus[/eluser]
I SEE THAT YOU SOLVED THIS. I JUST FINISHED MY EXAMPLE FOR YOU...

This is along the lines of my suggestion:

Code:
function edit_creditor($UniqContactID = '')
{
    /**
     * Edit a creditor given then UniqContactID
     * throws  to an editing screen
     */
    $this->load->helper('form');
    $this->load->model('creditors_model');
    $this->load->helper('form');
    $this->load->library('form_validation');

    $data['css'] = $this->css;
    $data['images'] = $this->images;
    $data['jss'] = $this->jss;
    $data['base'] = $this->base;
    $data['robots'] = '<meta name="robots" content="noindex,nofollow">';
    $data['title']="Creditors";  //shows up on tab
    $data['pagetitle']="Screen for Creditors";  //top of page body

    $this->form_validation->set_rules('CategoryID','CategoryID', 'required');
    $this->form_validation->set_rules('Company', 'Company', 'required|min_length[80]');
    $this->form_validation->set_rules('SearchName', 'SearchName', 'required');
    $this->form_validation->set_rules('Building','Building', 'required');
    $this->form_validation->set_rules('StreetNumber','StreetNumber', 'required');
    $this->form_validation->set_rules('Unit','Unit', 'required');
    $this->form_validation->set_rules('StreetNumberSuffix','StreetNumberSuffix', 'required');
    $this->form_validation->set_rules('StreetName','StreetName', 'required');
    $this->form_validation->set_rules('StreetType','StreetType', 'required');
    $this->form_validation->set_rules('StreetDirection','StreetDirection', 'required');
    $this->form_validation->set_rules('Municipality','Municipality', 'required');
    $this->form_validation->set_rules('ProvinceState','ProvinceState', 'required');
    $this->form_validation->set_rules('PostalCodeZip','PostalCodeZip', 'required');
    $this->form_validation->set_rules('Country','Country', 'required');
    $this->form_validation->set_rules('LTCCode','LTCCode', 'required');
    $this->form_validation->set_rules('GovernmentCode','GovernmentCode', 'required');
    $this->form_validation->set_rules('PrivacyPolicyExempt','PrivacyPolicyExempt', 'required');
    $this->form_validation->set_rules('ProofOfClaimRequired','ProofOfClaimRequired', 'required');
    $this->form_validation->set_rules('AdditionalInformation','AdditionalInformation', 'required');


    //initialize your variables

    if ( $this->input->post('CategoryID') !== FALSE ) {            

        $data['BtnSaveCredType'] = 'Save Revised Changes';

        // let's not load them again from the database but we must initialize them.
        // set_value will use the POST variables if detected.

        $data['CategoryID'] = '';
        $data['Company'] = '';
        $data['SearchName'] = '';
        $data['Building'] = '';
        $data['StreetNumber'] = '';
        $data['Unit'] = '';
        $data['StreetNumberSuffix'] = '';
        $data['StreetName'] = '';
        $data['StreetType'] = '';
        $data['StreetDirection'] = '';
        $data['Municipality'] = '';
        $data['ProvinceState'] = '';
        $data['PostalCodeZip'] = '';
        $data['Country'] = '';
        $data['LTCCode'] = '';
        $data['GovernmentCode'] = '';
        $data['PrivacyPolicyExempt'] = '';
        $data['ProofOfClaimRequired'] = '';
        $data['AdditionalInformation'] = '';
    } else {

        $data['BtnSaveCredType'] = 'Save Revised Changes';

        // original page load, let's get the database data
        $creditors = $this->creditors_model->get_creditor($UniqContactID)->row_array();
        // array keys built form row_array must match exactly to avoid the undefined notice.
        $data = array_merge($data, $creditors);
    }

    //okay, now we've setup variables let's actually validate the form and decide if we should proceed to
    // really save reuslts.

    if ($this->form_validation->run() === FALSE) {
        $this->load->view('header_view',$data);
        $this->load->view('menu_view');
        $this->load->view('creditor_edit_view', $data);  
        $this->load->view('footer_view',$data);
    } else {
        // call model to save data  here.

        redirect('path/to/success/page');
    }
}

Glad you got it working.


Messages In This Thread
Edit, validate, re-edit issue using set_value with optional parameter - by El Forum - 03-19-2010, 01:07 PM



Theme © iAndrew 2016 - Forum software by © MyBB