Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

File Upload Problem with Custom Forms


Go to End


2 Posts   1806 Views

Avatar
VicfromPerth

Community Member, 8 Posts

1 June 2012 at 3:52pm

Edited: 01/06/2012 3:54pm

Hi

I am pretty new to Silverstripe and I need to create a custom form that uploads a file. I have gotten the form to save to the database no problems, but I keep getting a '[User Error] Bad RecordClassName '' and $baseClass not set' error when I try to upload the file.

This is some of the code I am using:

class FormsPage extends Page {
	static $db = array(
		'Date' => 'Date',
		'CompanyName' => 'Varchar(100)',
		'ContactName' => 'Varchar(100)',
		'Phone' => 'Varchar(20)',
		'Fax' => 'Varchar(20)',
		'Email' => 'Varchar(100)',
		'Event' => 'Varchar(200)',
		'Stand' => 'Varchar(50)',
		'Fascia' => 'Varchar(100)',
		'Quantity' => 'Int(10)',
		'FormType'=> 'Varchar(20)',
		'Centered'=> 'Varchar(1)',
		'Logo1'=> 'Varchar(1)',
		'Logo2'=> 'Varchar(1)',
		'Printed'=> 'Varchar(1)',
		'Comments'=> 'Text',
		'TextColour'=>'Varchar(50)',
		'FasciaColour' => 'Varchar(50)',
		'Artwork' => 'Varchar(200)'        /*This is the field for the image, it is not required. I have tried setting it to File, but then I get errors when I run dev/build*/
					
	); 

I have tried adding 'Artwork' => 'File' to the public static $has_one = array section, but this has not worked for me either.

Then I create the form fields with the file field being

new FileField("Artwork","Upload Artwork", "", "", "", "assets/Uploads/")

I have also tried

$uploadify = new FileUploadField('Artwork','Upload Artwork');
$uploadify->setVar('buttonText','Upload File');

But then I do not get the browse button to display (it shows the title 'Upload Artwork', but not the button).

Then the code that processes the form is

function FasciaAction($data, $form) {
		
					if(isset($_FILES['Artwork'])) {
						
						// create the file from post data
						$upload = new Upload();
						$file = new File();
												
						$upload->loadIntoFile($_FILES['Artwork'], $file);

						// write file to form field
						$submittedField->UploadedFileID = $file->ID;
											
					}									
				

		
		// Create a new forms object and load the form data into it
		$fascia = new FormsPage();
		$form->saveInto($fascia);
 
		$fascia->write();
		
		// Redirect to a page thanking people for registering
		Director::redirect('thank-you/');
 
		 
	}

If anyone can point me in the right direction as to what I am missing that would be awesome.

Thanks!

Avatar
swaiba

Forum Moderator, 1899 Posts

6 June 2012 at 12:17am

Try SimpleImageField instead - and if you have trouble with the upload of an image here is some code for that...

$up =new Upload();
$imgLogo = Object::create('Image');
$up->loadIntoFile($data['Logo'], $imgLogo, 'Uploads');
if($up->isError()) {
   //handle error here
}