Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » UploadField on Frontendform

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

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

Page: 1
Go to End
Author Topic: 476 Views
  • Andre
    Community Member
    126 Posts

    UploadField on Frontendform Link to this post

    Hi there,

    it seems that the UploadField isn't working correctly on the Frontendforms.

    I will show some code and give Explanation afterwards:

    // Add Form inside Controller
    public function MitarbeiterAddForm(){

    $data = Session::get("FormInfo.Form_MitarbeiterAddForm.data");

    $avatarField = new UploadField('Avatar', 'Mitarbeiter Photo');
    $avatarField->allowedExtensions = array('jpg', 'gif', 'png');
    //print_r($avatarField->getAttributes()); die();

    // Create fields
    $fields = new FieldList(
    new TextField('Name', 'Name'),

    // Create actions
    $actions = new FieldList(
    new FormAction('doAdd', 'Mitarbeiter anlegen')

    $requiredFields = new RequiredFields(

    $form = new Form($this, 'MitarbeiterAddForm', $fields, $actions, $requiredFields);

    return $form;

    public function doAdd($data, $form){

    $errors = false;

    if($Mitarbeiter = DataObject::get_one('Mitarbeiter', "Name='".Convert::raw2sql($data['Name'])."'")){
    $form->addErrorMessage('Name', 'Ein Mitarbeiter mit diesem namen existiert bereits.', 'bad');
    $errors = true;

    Session::set("FormInfo.Form_MitarbeiterAddForm.data", $data);
    return $this->redirectBack();

    $o_Mitarbeiter = new Mitarbeiter();


    // return Director::redirect($this->URLSegment.'/profile');
    // We use Email Verified Member
    return $this->redirect('mitarbeiter01/all');

        * Show the registration form
       public function all(){

    $tmpPage = new Page();
    $tmpPage->Title = 'Mitarbeiter';
    $tmpPage->URLSegment = self::$url_segment;
    $tmpPage->ID = -1; // Set the page ID to -1 so we dont get the top level pages as its children
    $controller = new BaseController01($tmpPage);

    // WebApps
    if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
    //$CurrentWebApps = Member::currentUser()->WebApps()->getRange((int)$_GET['start'], 10);

    $customisedController = $controller->customise(array(
    'Title' => 'Mitarbeiter',
    'Content' => "<p>Mitarbeiter Liste</p>",
    "Form" => $this->MitarbeiterAddForm(),
    "Mitarbeiter" => DataObject::get('Mitarbeiter', '', '', '', (int)$_GET['start'].", 10")
    return $customisedController->renderWith(array('MitarbeiterController_all', 'MitarbeiterController0, 'Page', $this->owner->stat('template_main'), 'ContentController'));

    I use a Controller without the Pageobject (with its routes set up by routes.yml).
    This controller has an AddForm (as you can see) where I want to add "Miitarbeiter" to the System.

    The Mitarbeiter has a name ($db) and an Avatar ($has_one, 'Avatar' => 'Image');

    On Silverstripe 2.3.x/2.4.x in was able to use SimpleImageFiled in these cases.
    On SS3 SimpleImageFiled is marked as deprecated, so I tried with UploadField.

    First question, how can I customize UploadField, to hide the "From Files" Button.

    If I drag'n'drop or Upload a File from Computer, The Thumbnail is shown within my Form. But when I set the Avatar Field to be required, it returns the warning on Formsubmit, that the field isn't filled.
    Also, the Image ID is not written into the "Mitarbeiter"-Object that was added.

    Is this a Bug or am I missing something.



Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.