• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need example form repopulation with session data

#1
[eluser]moonbeetle[/eluser]
(form validation library CI 1.7.0)

Hi, I want to repopulate a form, using the Form Validation library, with session data (if the data exists). I was thinking about something like this:

Code:
if ($this->form_validation->run() == FALSE)
        {
            //Not OK OR validation hasn't run yet

            // Check for session data
            if($this->session->userdata("myform_data"))
            {

                // Repopulate form with session data

            }
            else
            {

                // Blank form - initial state
                $data = array();

            }
        }
        else
        {
            // OK - Do stuff with validated input data
        }

Is there a method I can use to repopulate from fields?
Something like:

Code:
$this->form_validation->fieldname = "some value";
or
$this->form_validation->set_value('fieldname','some value');

(both don't work)

#2
[eluser]jozeunico[/eluser]
Look at the form validation class for re-populating the form

Code:
<html>
<head>
<title>My Form</title>
</head>
<body>

<?php echo validation_errors(); ?>

<?php echo form_open('form'); ?>

<h5>Username</h5>
&lt;input type="text" name="username" value="&lt;?php echo set_value('username'); ?&gt;" size="50" /&gt;

<h5>Password</h5>
&lt;input type="text" name="password" value="&lt;?php echo set_value('password'); ?&gt;" size="50" /&gt;

<h5>Password Confirm</h5>
&lt;input type="text" name="passconf" value="&lt;?php echo set_value('passconf'); ?&gt;" size="50" /&gt;

<h5>Email Address</h5>
&lt;input type="text" name="email" value="&lt;?php echo set_value('email'); ?&gt;" size="50" /&gt;

<div>&lt;input type="submit" value="Submit" /&gt;&lt;/div>

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.