Jump to:

1970 Posts in 1272 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » SOLVED: How can I get a mini enquiry form on everey page?

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

Page: 1
Go to End
Author Topic: 451 Views
  • LinseyM
    Avatar
    Community Member
    99 Posts

    SOLVED: How can I get a mini enquiry form on everey page? Link to this post

    Hi there,

    Not quite sure how to go about this, but a client has asked for a "mini enquiry form" (name, email, message) on the right hand side of every page. How do I do this without having to make all pages into "Form" page types?

    I've done a few searches in the forums etc, but can't find what I'm looking for, so hoping someone can point me in the right direction.

    Many thanks,

    Linsey

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: SOLVED: How can I get a mini enquiry form on everey page? Link to this post

    You don't have to make a special page type just to put a form on a page.
    Put this or some version of this in your Page_Controller then you can use this form pretty much anywhere on your site.
    Just write $EnquiryForm in the template and that should print the form.

    public function EnquiryForm() {
       $fields = new FieldSet(
          new TextField("Name", "Name"),
             new EmailField('Email', 'Email'),
             new TextareaField("Message", "Message")
          );
          
    $actions = new FieldSet(
    new FormAction('ProcessEnquiryForm', 'Submit')
    );

    return new Form($this, 'EnquiryForm', $fields, $actions);
    }

    public function ProcessEnquiryForm($data, $form) {
       // Process form here...
    }

    How you save/process the data is up to you of course.

  • LinseyM
    Avatar
    Community Member
    99 Posts

    Re: SOLVED: How can I get a mini enquiry form on everey page? Link to this post

    Thanks for that.

    I've been thinking about it a bit more and I was wondering if there was some way to create a form page (thats hidden from the site), and then call the form itself from this page and show it on any page within the site? (That way the client could edit the form in the CMS if they wanted to).

    Cheers, L x

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: SOLVED: How can I get a mini enquiry form on everey page? Link to this post

    Are you talking about the UserForms module?

    In that case you might be able to create a page on the site that isn't visible in menus and then fetch that with a function.
    Something like

    function UserDefinedForm() {
    $form = DataObject::get_by_id("UserDefinedForm", $yourId);
    $controller = new UserDefinedForm_Controller($form);
    return $controller->Form();
    }

    Haven't tried this myself though so I'm not sure if the form will work on another page like this.

  • LinseyM
    Avatar
    Community Member
    99 Posts

    Re: SOLVED: How can I get a mini enquiry form on everey page? Link to this post

    OK, that would make sense... I will give it a try and see how I get on.

    Cheers!

  • LinseyM
    Avatar
    Community Member
    99 Posts
    451 Views
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.