CodeIgniter Forums
set_value from $_POST array, No Validation - 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: set_value from $_POST array, No Validation (/showthread.php?tid=19159)



set_value from $_POST array, No Validation - El Forum - 05-29-2009

[eluser]glasses092[/eluser]
Hey guys,

I am trying to set to get my form to re-populate after I click the submit button.
I am not using the validation library.

Basically, what I want to happen is that there is a default value in the 'name' textbox when the page is loaded first, then when a user enters a new value in the textbox and submits the form, this value is remembered...

Does anyone have any ideas?

Code:
function test_validation() {
    //Form
    $test_form = form_open(current_url());
        $test_form .= form_label('Name', 'name') . form_input('name', set_value('name as','default value'));
        $test_form .= form_label('Email Address', 'email_address') . form_input('email_address', '[email protected]');
        $test_form .= form_submit('submit_btn', 'Submit');
    $test_form .=form_close();
    echo $test_form;
    
    //Form posted back
    if( $this->input->post('submit_btn') ) {
        echo 'The form was posted back.<br />';
        
        foreach (($_POST) as $key => $value) {
            echo "$key:$value<br />";
            set_value($key,$value);
        }

    }
}

Thanks,

Martin


set_value from $_POST array, No Validation - El Forum - 05-29-2009

[eluser]TheFuzzy0ne[/eluser]
set_value() is usually used in a view, and it accepts two parameters. The field name, and the default value, not a key and a value.


set_value from $_POST array, No Validation - El Forum - 05-30-2009

[eluser]darkhouse[/eluser]
Use the form validation library.