CodeIgniter Forums
Edit, validate, re-edit issue using set_value with optional parameter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Edit, validate, re-edit issue using set_value with optional parameter (/showthread.php?tid=28706)

Pages: 1 2 3


Edit, validate, re-edit issue using set_value with optional parameter - El Forum - 03-18-2010

[eluser]billmce[/eluser]
Maybe I'm just missing something simple ... but I've spent hours and hours on this.

I can retrieve data (in this example using $data['Company'] )from mysql and use it to populate a view:

<input type="text" name="Company" value="<?php echo $Company; ?>" />

After loading the form_validation library, I can then validate the data on the form that the user modified and if I find an error force a re-edit and re-displaying the data:

<input type="text" name="Company" value="<?php echo set_value('Company'); ?>" />

But doing this requires me to maintain two forms -- one for the first edit, and another for subsequent edits.

After checking out set_value I thought I'd found the answer.
<input type="text" name="Company" value="<?php echo set_value('Company',$Company); ?>" />

but I get strange results after a validation failure (here entering data "Test Company Name"):

The input box is filled with <div style= followed by.

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: Company

Filename: views/creditor_edit_view.php

Line Number: 57
Test Company Name" />


Any ideas on why the set_value option problem?

I'm completely stumped and frustrated.

Surely I don't need 2 forms to edit/validate/re-edit?


Edit, validate, re-edit issue using set_value with optional parameter - El Forum - 03-18-2010

[eluser]Ben Edmunds[/eluser]
That code looks right.

You can try viewing source on the page and see what exactly is being outputted to the browser.


Edit, validate, re-edit issue using set_value with optional parameter - El Forum - 03-18-2010

[eluser]bretticus[/eluser]
You certainly don't need two forms. Form validation works best when the controller loads the view form and the form action is set to the very same controller path.

Typically the controller looks like...

Declare all the rules for the form (even on the initial pageload.)

Run the validation libs Run() method.
if it fails, load the view with the form. It will always fail the first time because there is no post data yet.

In your view, set_value() should work as long as you are setting the array keys in accordance with the variable names in your view. Make sure you initialize these variables so that they are empty arrays elements at least to avoid Undefined Variable notices (not errors.)


Edit, validate, re-edit issue using set_value with optional parameter - El Forum - 03-19-2010

[eluser]billmce[/eluser]
I've been using the value of the submit button to determine whether this was the first run through the form or not.
If it was the first run through the form I go and get the data to populate the form, then set the submit button value.

If the submit button had a value I know it's a re-edit and then I can validate, save etc.
Newbie alert.

The Controller function
=======================
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'] = '&lt;meta name="robots" content="noindex,nofollow"&gt;';
        $data['title']="Creditors";  //shows up on tab
        $data['pagetitle']="Screen for Creditors";  //top of page body
        
        if(empty($_POST['BtnSaveCredType']))
        {
            //We haven't got any data yet .. ie) first time in record.
              foreach ($this->creditors_model->get_creditor($UniqContactID)->result_array() as $keyname => $cred)
              {
                //Break the data into individual fields
                $data['CategoryID'] = $cred['CategoryID'];
                $data['Company'] = $cred['Company'];
                $data['SearchName'] = $cred['SearchName'];
                $data['Building'] = $cred['Building'];
                $data['StreetNumber'] = $cred['StreetNumber'];
                $data['Unit'] = $cred['Unit'];
                $data['StreetNumberSuffix'] = $cred['StreetNumberSuffix'];
                $data['StreetName'] = $cred['StreetName'];
                $data['StreetType'] = $cred['StreetType'];
                $data['StreetDirection'] = $cred['StreetDirection'];
                $data['Municipality'] = $cred['Municipality'];
                $data['ProvinceState'] = $cred['ProvinceState'];
                $data['PostalCodeZip'] = $cred['PostalCodeZip'];
                $data['Country'] = $cred['Country'];
                $data['LTCCode'] = $cred['LTCCode'];
                $data['GovernmentCode'] = $cred['GovernmentCode'];
                $data['PrivacyPolicyExempt'] = $cred['PrivacyPolicyExempt'];
                $data['ProofOfClaimRequired'] = $cred['ProofOfClaimRequired'];
                $data['AdditionalInformation'] = $cred['AdditionalInformation'];            
              }

            $data['BtnSaveCredType'] = 'Save Changes';
            // now go in and bring up the form.
            $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
        {
            echo "Button not empty -- s/b saving";
            
            //NOTE: 'set_value' ONLY works on fields that are being validated.
            //      I think you must have a rule for each field you intend to use with set_value
            $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');        
            $data['BtnSaveCredType'] = 'Save Revised Changes';
            if ($this->form_validation->run() == FALSE)
            {
            
                $this->load->view('header_view',$data);
                $this->load->view('menu_view');
                $this->load->view('creditor_edit_view2', $data);  
                $this->load->view('footer_view',$data);
                
            }
            else
            {
                // call model to save data  here.
                
            }
            
        };
    
    }



Edit, validate, re-edit issue using set_value with optional parameter - El Forum - 03-19-2010

[eluser]billmce[/eluser]
In the controller function I'm still showing 'creditor_edit_view1' and 'creditor_edit_view2' (my workaround) instead of the goal of a single form 'creditor_edit_view'.

This is the 'creditor_edit_view' VIEW
====================================
Code:
<h1>&lt;?php echo $title; ?&gt;</h1>
&lt;?php
echo validation_errors();  // if we're saving, and find errors ... show 'em here.
?&gt;
&lt;?php

echo form_open('creditors/edit_creditor');

?&gt;

<fieldset>
<legend>Company Information</legend>
    <ol>
    <li><label for="CategoryID">CategoryID:</label>
    &lt;?php // without quotes -- no data , with quotes data but <div issue ?&gt;
        &lt;input type="text" name="CategoryID" value="&lt;?php echo set_value('CategoryID',$CategoryID); ?&gt;"  /&gt;&lt;/li>
    
    <li><label for="Company">Company:</label>
    &lt;input type="text" name="Company" value="&lt;?php echo set_value('Company',$Company); ?&gt;"  /&gt;&lt;/li>


    <li><label for="SearchName">SearchName:</label>
    &lt;input type="text" name="SearchName" value="&lt;?php echo set_value('SearchName',$SearchName); ?&gt;"  /&gt;&lt;/li>
    </ol>

</fieldset>

<fieldset>
<legend>Address Information</legend>
    <ol>
    <li><label for="Building">Building:</label>
    &lt;input type="text" name="Building" value="&lt;?php echo set_value('Building', $Building); ?&gt;"  /&gt;&lt;/li>
    
    <li><label for="StreetNumber">StreetNumber:</label>
    &lt;input type="text" name="StreetNumber" value="&lt;?php echo set_value('StreetNumber', $StreetNumber); ?&gt;"  /&gt;&lt;/li>
    
    <li><label for="Unit">Unit:</label>
    &lt;input type="text" name="Unit" value="&lt;?php echo set_value('Unit', $Unit); ?&gt;"  /&gt;&lt;/li>
    
    <li><label for="StreetNumberSuffix">Suffix: </label>
    &lt;input type="text" name="StreetNumberSuffix" value="&lt;?php echo set_value('StreetNumberSuffix', $StreetNumberSuffix); ?&gt;"  /&gt;&lt;/li>
    
    <li><label for="StreetName">StreetName:</label>
    &lt;input type="text" name="StreetName" value="&lt;?php echo set_value('StreetName', $StreetName); ?&gt;"  /&gt;&lt;/li>
    
    <li><label for="StreetType">StreetType:</label>
    &lt;input type="text" name="StreetType" value="&lt;?php echo set_value('StreetType', $StreetType); ?&gt;"  /&gt;&lt;/li>
    
    <li><label for="StreetDirection">StreetDirection:</label>
    &lt;input type="text" name="StreetDirection" value="&lt;?php echo set_value('StreetDirection', $StreetDirection); ?&gt;"  /&gt;&lt;/li>
    
    <li><label for="Municipality">Municipality:</label>
    &lt;input type="text" name="Municipality" value="&lt;?php echo set_value('Municipality', $Municipality); ?&gt;"  /&gt;&lt;/li>
    
    <li><label for="ProvinceState">ProvinceState:</label>
    &lt;input type="text" name="ProvinceState" value="&lt;?php echo set_value('ProvinceState', $ProvinceState); ?&gt;"  /&gt;&lt;/li>
    
    <li><label for="PostalCodeZip">PostalCodeZip</label>
    &lt;input type="text" name="PostalCodeZip" value="&lt;?php echo set_value('PostalCodeZip', $PostalCodeZip); ?&gt;"  /&gt;&lt;/li>
    
    <li><label for="Country">Country:</label>
    &lt;input type="text" name="Country" value="&lt;?php echo set_value('Country', $Country); ?&gt;"  /&gt;&lt;/li>
    </ol>
</fieldset>
<fieldset>
<legend>Miscellaneous</legend>
    <ol>
    <li><label for="LTCCode">LTCCode:</label>
    &lt;input type="text" name="LTCCode" value="&lt;?php echo set_value('LTCCode', $LTCCode); ?&gt;"  /&gt;&lt;/li>
    
    <li><label for="GovernmentCode">GovernmentCode</label>
    &lt;input type="text" name="GovernmentCode" value="&lt;?php echo set_value('GovernmentCode', $GovernmentCode); ?&gt;"  /&gt;&lt;/li>
    
    <li><label for="PrivacyPolicyExempt">PrivacyPolicyExempt:</label>
    &lt;input type="text" name="PrivacyPolicyExempt" value="&lt;?php echo set_value('PrivacyPolicyExempt', $PrivacyPolicyExempt); ?&gt;"  /&gt;&lt;/li>
    
    <li><label for="ProofOfClaimRequired">ProofofClaimRequired:</label>
    &lt;input type="text" name="ProofOfClaimRequired" value="&lt;?php echo set_value('ProofOfClaimRequired', $ProofOfClaimRequired); ?&gt;"  /&gt;&lt;/li>
    
    <li><label for="AdditionalInformation">Additional Information:</label>
    &lt;input type="text" name="AdditionalInformation" value="&lt;?php echo set_value('AdditionalInformation', $AdditionalInformation); ?&gt;"  /&gt;&lt;/li>
    </ol>
</fieldset>

<fieldset class="submit">
    &lt;?php echo form_submit('BtnSaveCredType',$BtnSaveCredType); ?&gt;
</fieldset>
&lt;?php



Edit, validate, re-edit issue using set_value with optional parameter - El Forum - 03-19-2010

[eluser]billmce[/eluser]
The Output Source
=================
[code]
Button not empty -- s/b saving
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>&lt;html &gt;
&lt;head&gt;

&lt;title&gt;Creditors&lt;/title&gt;

&lt;meta name="robots" content="noindex,nofollow"&gt;
[removed][removed]

&lt;link rel="stylesheet" type="text/css" href="http://localhost/cif/application/css/styles.css"/&gt;



&lt;/head&gt;
&lt;body&gt;



<div id="wrapper">
<div id="header" class="center">&lt;!-- Header --&gt;
<img src="http://localhost/cif/application/images/logo.jpg" alt="logo" id="logo"/>
</div> &lt;!-- Header --&gt;

<div id='content' class='center'>

<div id="topnav" class="center">
<ul>
<li>Creditors</li>

<li>Banking</li>
<li>SRD</li>
<li>Test</li>
</ul>
<div class="clear"></div>
</div>

<h1>Creditors</h1>
<p>The Company field must be at least 80 characters in length.</p>
<p>The Building field is required.</p>
<p>The Unit field is required.</p>
<p>The StreetNumberSuffix field is required.</p>
<p>The StreetDirection field is required.</p>
<p>The AdditionalInformation field is required.</p>
&lt;form action="http://localhost/cif/creditors/edit_creditor" method="post"&gt;
<fieldset>
<legend>Company Information</legend>

<ol>
<li><label for="CategoryID">CategoryID:</label>
&lt;input type="text" name="CategoryID" value="&lt;div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined variable: CategoryID</p>
<p>Filename: views/creditor_edit_view.php</p>

<p>Line Number: 55</p>

</div>1"
/></li>

<li><label for="Company">Company:</label>
&lt;input type="text" name="Company" value="&lt;div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined variable: Company</p>

<p>Filename: views/creditor_edit_view.php</p>
<p>Line Number: 58</p>

</div>Test Company Name" />
</li>


<li><label for="SearchName">SearchName:</label>
&lt;input type="text" name="SearchName" value="&lt;div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined variable: SearchName</p>
<p>Filename: views/creditor_edit_view.php</p>
<p>Line Number: 62</p>

</div>Test Company Search Name" /></li>
</ol>

</fieldset>

<fieldset>

<legend>Address Information</legend>
<ol>
<li><label for="Building">Building:</label>
&lt;input type="text" name="Building" value="&lt;div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined variable: Building</p>
<p>Filename: views/creditor_edit_view.php</p>

<p>Line Number: 71</p>

</div>" /></li>

<li><label for="StreetNumber">StreetNumber:</label>
&lt;input type="text" name="StreetNumber" value="&lt;div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined variable: StreetNumber</p>

<p>Filename: views/creditor_edit_view.php</p>
<p>Line Number: 74</p>

</div>60" /></li>

<li><label for="Unit">Unit:</label>
&lt;input type="text" name="Unit" value="&lt;div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>

<p>Message: Undefined variable: Unit</p>
<p>Filename: views/creditor_edit_view.php</p>
<p>Line Number: 77</p>

</div>" /></li>

<li><label for="StreetNumberSuffix">Suffix: </label>
&lt;input type="text" name="StreetNumberSuffix" value="&lt;div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined variable: StreetNumberSuffix</p>
<p>Filename: views/creditor_edit_view.php</p>
<p>Line Number: 80</p>

</div>" /></li>

<li><label for="StreetName">StreetName:</label>
&lt;input type="text" name="StreetName" value="&lt;div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined variable: StreetName</p>
<p>Filename: views/creditor_edit_view.php</p>
<p>Line Number: 83</p>

</div>TestTest" /></li>

<li><label for="StreetType">StreetType:</label>
&lt;input type="text" name="StreetType" value="&lt;div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined variable: StreetType</p>
<p>Filename: views/creditor_edit_view.php</p>
<p>Line Number: 86</p>

</div>St" /></li>

<li><label for="StreetDirection">StreetDirection:</label>
&lt;input type="text" name="StreetDirection" value="&lt;div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4
[code]


Edit, validate, re-edit issue using set_value with optional parameter - El Forum - 03-19-2010

[eluser]billmce[/eluser]
Some <div> styling is trying to be applied to the values -- only when there is $_POST data.

I'm confused as to how I would lay out that code for getting the data on the first iteration of the view, and then not getting it for subsequent iterations of the view using just the form_validation run status.

Once I get past edit/validate/re-edit I hope to extend this to 'add' ... so any comments in that direction also appreciated.

TIA.


Edit, validate, re-edit issue using set_value with optional parameter - El Forum - 03-19-2010

[eluser]Ben Edmunds[/eluser]
Try this controller:

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'] = '&lt;meta name="robots" content="noindex,nofollow"&gt;';
        $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');

            $this->form_validation->run();

        
        if(empty($_POST['BtnSaveCredType']))
        {
            //We haven't got any data yet .. ie) first time in record.
              foreach ($this->creditors_model->get_creditor($UniqContactID)->result_array() as $keyname => $cred)
              {
                //Break the data into individual fields
                $data['CategoryID'] = $cred['CategoryID'];
                $data['Company'] = $cred['Company'];
                $data['SearchName'] = $cred['SearchName'];
                $data['Building'] = $cred['Building'];
                $data['StreetNumber'] = $cred['StreetNumber'];
                $data['Unit'] = $cred['Unit'];
                $data['StreetNumberSuffix'] = $cred['StreetNumberSuffix'];
                $data['StreetName'] = $cred['StreetName'];
                $data['StreetType'] = $cred['StreetType'];
                $data['StreetDirection'] = $cred['StreetDirection'];
                $data['Municipality'] = $cred['Municipality'];
                $data['ProvinceState'] = $cred['ProvinceState'];
                $data['PostalCodeZip'] = $cred['PostalCodeZip'];
                $data['Country'] = $cred['Country'];
                $data['LTCCode'] = $cred['LTCCode'];
                $data['GovernmentCode'] = $cred['GovernmentCode'];
                $data['PrivacyPolicyExempt'] = $cred['PrivacyPolicyExempt'];
                $data['ProofOfClaimRequired'] = $cred['ProofOfClaimRequired'];
                $data['AdditionalInformation'] = $cred['AdditionalInformation'];            
              }

            $data['BtnSaveCredType'] = 'Save Changes';
            // now go in and bring up the form.
            $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
        {
            echo "Button not empty -- s/b saving";
            
            //NOTE: 'set_value' ONLY works on fields that are being validated.
            //      I think you must have a rule for each field you intend to use with set_value      
            $data['BtnSaveCredType'] = 'Save Revised Changes';
            if ($this->form_validation->run() == FALSE)
            {
            
                $this->load->view('header_view',$data);
                $this->load->view('menu_view');
                $this->load->view('creditor_edit_view2', $data);  
                $this->load->view('footer_view',$data);
                
            }
            else
            {
                // call model to save data  here.
                
            }
            
        };
    
    }


In order to use set_value the first time through you have to declare all of the fields.


Edit, validate, re-edit issue using set_value with optional parameter - El Forum - 03-19-2010

[eluser]billmce[/eluser]
Still sucking mud .. :-(

Revised controller (changed view's to 'creditor_edit_view') the rest is as per your change.
==================
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'] = '&lt;meta name="robots" content="noindex,nofollow"&gt;';
        $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');
        
        $this->form_validation->run(); //will fail on run thru because no post data

        
        if(empty($_POST['BtnSaveCredType']))
        {
            //We haven't got any data yet .. ie) first time in record.
              foreach ($this->creditors_model->get_creditor($UniqContactID)->result_array() as $keyname => $cred)
              {
                //Break the data into individual fields
                $data['CategoryID'] = $cred['CategoryID'];
                $data['Company'] = $cred['Company'];
                $data['SearchName'] = $cred['SearchName'];
                $data['Building'] = $cred['Building'];
                $data['StreetNumber'] = $cred['StreetNumber'];
                $data['Unit'] = $cred['Unit'];
                $data['StreetNumberSuffix'] = $cred['StreetNumberSuffix'];
                $data['StreetName'] = $cred['StreetName'];
                $data['StreetType'] = $cred['StreetType'];
                $data['StreetDirection'] = $cred['StreetDirection'];
                $data['Municipality'] = $cred['Municipality'];
                $data['ProvinceState'] = $cred['ProvinceState'];
                $data['PostalCodeZip'] = $cred['PostalCodeZip'];
                $data['Country'] = $cred['Country'];
                $data['LTCCode'] = $cred['LTCCode'];
                $data['GovernmentCode'] = $cred['GovernmentCode'];
                $data['PrivacyPolicyExempt'] = $cred['PrivacyPolicyExempt'];
                $data['ProofOfClaimRequired'] = $cred['ProofOfClaimRequired'];
                $data['AdditionalInformation'] = $cred['AdditionalInformation'];            
              }

            $data['BtnSaveCredType'] = 'Save Changes';
            // now go in and bring up the form.
            $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
        {
            //We're into re-editing
            $data['BtnSaveCredType'] = 'Save Revised Changes';
            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.
                
            }
            
        };
    
    }

A short clip of the view (unchanged from before):

<li><label for="Company">Company:</label>
&lt;input type="text" name="Company" value="&lt;div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message: Undefined variable: Company</p>
<p>Filename: views/creditor_edit_view.php</p>

<p>Line Number: 58</p>

</div>Test Company Name" /></li>

--
Still scratching my pounding head. I appreciate you taking the time to look this over.


Edit, validate, re-edit issue using set_value with optional parameter - El Forum - 03-19-2010

[eluser]Ben Edmunds[/eluser]
Are you sure you're getting into the correct if/else block?

Also, you should be using row_array() instead of result_array since you are only returning one row.

What happens if you do this?

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'] = '&lt;meta name="robots" content="noindex,nofollow"&gt;';
        $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');
        
        $this->form_validation->run(); //will fail on run thru because no post data

        
        if(empty($_POST['BtnSaveCredType']))
        {
            //We haven't got any data yet .. ie) first time in record.
            $creditors = $this->creditors_model->get_creditor($UniqContactID)->row_array();

            $data = array_merge($data, $creditors);
              

            $data['BtnSaveCredType'] = 'Save Changes';
            // now go in and bring up the form.
            $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
        {
            //We're into re-editing
            $data['BtnSaveCredType'] = 'Save Revised Changes';
            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.
                
            }
            
        };
    
    }