CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 $Component->SetValue() not working in AfterProcessFile Event. [CCS 3.2]

Print topic Send  topic

Author Message
pulsorock

Posts: 28
Posted: 09/09/2009, 1:46 PM

Hello,

I have a file upload component that has an AfterProcessFile event that copies the file to another folder and then updates a field column for that record. The problem I’m having is that the $Component->SetValue() is not working for setting that value to that specific field.

Here is an example code of the AfterProcessFile Custom code:

  
$original_path = "/var/www/file_upload/" . $component->file_upload->GetValue();    
$copy_path = "/var/www/file_backups/" . $component->file_upload->GetValue();    
    
if (!copy($original_path, $copy_path)) {    
    $component->Errors->addError(There was an error copying file.");    
}else{  
   $component->file_backup->SetValue($copy_path);  
}    

The files get copied fine, but the component field “file_backup” is still null after the update (or insert), it seems like the SetValue() is doing nothing.

I’ve tried these methods without success:
  
$component->file_backup->SetText($copy_path);  
$component->file_backup->SetValue($copy_path);  
$component->file_backup->Value = $copy_path;  

Any ideas of what could be wrong?
View profile  Send private message
jjrjr1


Posts: 942
Posted: 09/09/2009, 4:50 PM

By the time the After Process File Event is fired The database has already been updated.

Soo.... No database fields are updated during this event.

You must do these field updates during an event that is fired before any updates or inserts occur.

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
pulsorock

Posts: 28
Posted: 09/09/2009, 5:31 PM

Quote jjrjr1:
By the time the After Process File Event is fired The database has already been updated.

Soo.... No database fields are updated during this event.

You must do these field updates during an event that is fired before any updates or inserts occur.

I imagine it had something to do with that... So, what alternatives do I have to accomplish what I need? On what events prior to "AfterProcessFile" can I set those values?

Also, since I need that field be updated ONLY when a new file is uploaded to the server, how I can validate that a file is being uploaded rather than just a regular update to the record (on others fields other than the upload component)?

Thanks!
View profile  Send private message
jjrjr1


Posts: 942
Posted: 09/09/2009, 6:07 PM

If you want to validate the file is uploaded then you will have to do all that in the after process file

This means you do what ever checks you need to do. Then do the database update.

eg:

$db = new clsYourDBConnection();
$SQL = Your Sql Command String
$db->query($SQL);

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
pulsorock

Posts: 28
Posted: 09/10/2009, 10:35 AM

Thanks!

Is there a way (maybe an internal (CC param) to identify the ID (the incremental ID) of the record I'm working. If either is a new insert or an update of an existing record. So I could create a command string like:

$SQL = "update table set file_backup = '". $copy_path ."' where id = '". $component->id->Value ."'";
Where $component->id->Value would be someway to identify the ID of the current working record.

Thanks!
View profile  Send private message
jjrjr1


Posts: 942
Posted: 09/10/2009, 11:25 AM

Use the filename that was inserted into the database as the where= criteria

_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
View profile  Send private message
pulsorock

Posts: 28
Posted: 09/10/2009, 11:42 AM

Quote jjrjr1:
Use the filename that was inserted into the database as the where= criteria

That's a good suggestion... Will try it... thanks!
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.