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:

Form Questions /

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

How to call an Uploadify field in costumized form?

Go to End

6 Posts   2986 Views


Community Member, 25 Posts

18 September 2011 at 2:59am


How would you call an Uploadify field to be used in a costumized front end form? I'm aware of the function $dataFieldByName() which works well for most of my fields but it can't handle Date fields or an Uploadify field. I have managed to get the date fields working by calling all the necessary js and hard coding the metadata but what about an uploadify field? Calling all the js files makes the field appear but without the metadata no functionality. Is this even possible?

By letting Silverstripe scaffold the form it works well and I can achieve most of what I want by some css manipulating and jQuery but it would be so much cleaner if I could build my own template from ground up.

Ryan M.

Community Member, 309 Posts

18 September 2011 at 11:10pm

Can you paste your controller code? I'll tell you where to add the Uploadify field.


Community Member, 25 Posts

19 September 2011 at 5:42am

Edited: 19/09/2011 5:48am

Hi, and thanks for answering.

I have pasted here relevant parts of my controller and also parts of my template to further illustrate what i want to do.

By calling the form the "usual" way like below everything works well. My datefields and uploadify field works as expected. The problem with this approach is that costumising the form layout is, not impossible but, quite dounting.

<div class="typography">
	<div id="FormContainer">

What I would like is to "handcraft" my form template using $dataFieldByName() to render individual fields. This works fine for regular data fields but how to call a uploadify field. I have had some success calling it the way you can see in the template code by also calling all the js and by hardcoding metadata into the the template My question really is - Is there a correct way to call that field that makes it work in all its glory in a handcrafted front end form??

Found a quite similar problem here:

Part of the controller

class ApplicationPage_Controller extends Page_Controller

	public function init() {
	/* Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); */
	Requirements::javascript(SAPPHIRE_DIR . '/javascript/jquery_improvements.js');	
	Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery.ui.all.css');
	Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/jquery.ui.core.js');
	Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/jquery.ui.datepicker.js');
	Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/i18n/jquery.ui.datepicker-sv.js');	
	Requirements::javascript(THIRDPARTY_DIR . "/jquery-metadata/jquery.metadata.js");
	Requirements::javascript(SAPPHIRE_DIR . "/javascript/DateField.js");

	protected function ApplyForm() {
		$firstName = new TextField('FirstName', 'Förnamn');
		$lastName = new TextField('LastName', 'Efternamn');
// Lots of other fields here
		$supplements = new MultipleFileUploadField('Supplements', 'Ladda upp bilagor');
		/* $supplements->uploadOnSubmit(); */
		$fields = new FieldSet(
			// Lots of other fields
		$send = new FormAction('doApply', 'Skicka ansökan');
		$actions = new FieldSet($send);
		$validator = new RequiredFields(
		return new Form($this, 'ApplyForm', $fields, $actions, $validator);

	public function doApply($data, $form) {
		$form->saveInto($application = new Application());
		return array (
			'Application' => $application

And some template code

<% control ApplyForm %>

			<form $FormAttributes>
				<% if Message %>
					<p id="{$FormName}_error" class="message $MessageType">
				<% else %>
					<p id="{$FormName}_error" class="message $MessageType"></p>
				<% end_if %>
				<legend class="forminfo">&nbsp;&nbsp;Basinformation&nbsp;&nbsp;</legend>
				<div id="FirstName" class="field text group">
					<label class="left" for="Form_ApplyForm_FirstName">
					Sökandens förnamn<span class="required">*</span>
					<div class="middleColumn textColumn">
				<div id="LastName" class="field text group">
					<label class="left" for="Form_ApplyForm_LastName">
					Sökandens efternamn<span class="required">*</span>
					<div class="middleColumn textColumn">


			<!-- Loads of other fields here -->

				<div id="Supplements" class="field UploadifyField group">
					<label class="left" for="Form_ApplyForm_Supplements">
					Ladda upp bilagor<span class="required">*</span>
					<div class="middleColumn smallColumn">						
                                          <% include UploadifyField %>
				<% if Actions %>
					<div class="Actions">
						<% control Actions %>$Field<% end_control %>
				<% end_if %>

<% end_control %>

Ryan M.

Community Member, 309 Posts

19 September 2011 at 8:00am

You seem to be customizing it the correct way. I'd probably wait until UncleCheese notices this thread and provides his own insight.


Community Member, 12 Posts

5 January 2012 at 5:27am

from my understanding, the $dataFieldByName(field) looks for a function called Field which renders the form element. this doesn't exist on the uploadify class. The uploadify class is using the function FieldHolder

what you can do is add the following function to the uploadify class.

this is in the uploadify/code/UploadifyField.php

abstract class UploadifyField extends FormField
public function Field() {
return $this->FieldHolder();

However, when i upload a file, i get a HTTP error. I don't know if this is to do with the facebook connect module or if its something else. Uploadify does work in the admin tho, just not the front end. I haven't tried this without facebook connect.


Community Member, 12 Posts

5 January 2012 at 6:45am

just found out that u can use $dataFieldByName(field).FieldHolder so there is no need to change the code.