Welcome Guest, Not a member yet? Register   Sign In
Setting the default value of an input.
#1

[eluser]ElShotte[/eluser]
I have 4 fields that need to have a default value of 0. Naturally, their value is set to set_value('blah'). So I was thinking, if statements like so:

$field = 0;

if (isset($this->input->post('field'))) {
$ssincome = $this->input->post('field');
}

and set the value of the input to $field, but then for some reason when I load the page, it looks as if the CSS is not loaded because it is completely lacking style.

Any ideas? I've also checked this:

if (isset(set_value('pension'))) { $pension = set_value('pension'); }

But the truth is, what I really want to do is require only one of the 4 fields, so technically my method wouldn't be perfect cause the user could just leave the 4 zeros and the form would still go through = bad. Time to break out the CI manual again.
#2

[eluser]ElShotte[/eluser]
Code:
//--Form Validation - Retired--//
                    //-----------------------------//
                    
                    if ($totaljobs == '4') {
                    
                    $ssinc    = $this->input->post('cossincome');
                    $pens    = $this->input->post('copension');
                    $ann    = $this->input->post('coannuity');
                    $reti    = $this->input->post('coretirement');
                    
                    if ((!empty($ssinc)) or (!empty($pens)) or (!empty($ann)) or (!empty($reti)))
                        {
                            $this->form_validation->set_rules('cossincome', 'Social Security', 'trim|numeric');
                            $this->form_validation->set_rules('copension', 'Pension', 'trim|numeric');
                            $this->form_validation->set_rules('coannuity', 'Annuity', 'trim|numeric');
                            $this->form_validation->set_rules('coretirement', 'Retirement', 'trim|numeric');
                        }
                    else
                        {    
                            $this->form_validation->set_rules('cossincome', 'Social Security', 'trim|required|numeric');
                            $this->form_validation->set_rules('copension', 'Pension', 'trim|required|numeric');
                            $this->form_validation->set_rules('coannuity', 'Annuity', 'trim|required|numeric');
                            $this->form_validation->set_rules('coretirement', 'Retirement', 'trim|required|numeric');
                        }
                    }    
                            
                    //-------End of Form Validation-------//
                    //------------------------------------//

In the controller of course.




Theme © iAndrew 2016 - Forum software by © MyBB