Part of the EllisLab Network
   
 
Re-populating Input file after validation
Posted: 16 May 2008 03:27 AM   [ Ignore ]  
Summer Student
Total Posts:  15
Joined  05-05-2008

Hi,

I’m using CI validation with MY_form_helper.php.

In my form, I have an

input type="file"

.
To generate it, I have modified the helper MY_form_helper, adding this function to generate the input file.

function form_input_file($data = '', $value = '', $extra = '')
{
    $name
= ( ! is_array($data))?$data:((isset($data['name']))?$data['name']:'');
    
$value = (isset($_POST[$name]))?$_POST[$name]:((isset($_GET[$name]))?$_GET[$name]:$value);
    
$defaults = array('type' => 'file', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50');

    return
"<input ".parse_form_attributes($data, $defaults).$extra." />\n";
}

I just have modified the ‘type’ => ‘file’...

Unfortunately, after validation, the value of the input file is not saved ...

Does anyone have a solution ??

Thanks in advance,

Profile
 
 
Posted: 16 May 2008 03:41 AM   [ Ignore ]   [ # 1 ]  
Sr. Research Associate
RankRankRankRankRank
Total Posts:  3305
Joined  07-14-2006

There is no solution. It is a security measure in the browsers that prevents the selection of a file. Lets say a rogue site loads a file with paswords from your machine in a hidden file input because the browser has permission to browse your drive(s). You don’t want that to happen.

Profile
 
 
Posted: 16 May 2008 04:01 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  15
Joined  05-05-2008

Ok xwero ... I’m sad to read that ... but you are right: in term of security, I fully understand it ...

Thanks

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 64454 Total Logged-in Users: 18
Total Topics: 80961 Total Anonymous Users: 0
Total Replies: 435697 Total Guests: 199
Total Posts: 516658    
Members ( View Memberlist )