Styling the form block (custom template)

Permalink
I'd like to style the form block. I *thought* that I could do this by creating a custom template but it looks like the styling for the form block is in:

concrete>core>controllers>form_minisurvey.php 
(inside of the loadSurvey method)


However, if I change this then all the other forms in my site will be styled the same way?

Is there something I'm missing here?

 
cubewebsites replied on at Permalink Best Answer Reply
I wouldn't edit the core file directly. What you can do is copy concrete/blocks/form/controller.php to /blocks/form/controller.php

Copy the methods you want to override from concrete/core/controllers/blocks/form_minisurvey.php into your class

This will mean that all your blocks will use the markup generated by your new methods.

If you want to use the default styling on all forms except for this one then you can always give a block a particular name (using the "Form Name" attribute under "Options") when adding the form and then add a check at the top of your override method so for example if you were overriding the loadSurvey method you might have something like this:

function loadSurvey( $qsID, $showEdit=false, $bID=0, $hideQIDs=array(), $showPending=0 ){
    if($this->get('surveyName')!='Whatever name you use')
        return parent::loadSurvey($qsID,$showEdit,$bID,$hideQIDS,$showPending);
    // your custom code goes here
nicolechung replied on at Permalink Reply
Okay I have a another question.

I have a "controller" folder outside of the concrete folder, but I don't have a "core" folder.

form_minisurvey.php is in

concrete>core>controllers>form_minisurvey.php

Does this mean I can't / am not supposed to override the file?

I get how to override concrete controllers but this file is in concrete> core > controllers NOT concrete > controllers (generally if I want to override a concrete controller I just make a copy in my controllers folder, right?)

SO, do I just create a core folder, put "controllers" in the "core" folder, and put my form_minisurvey.php controller class there?
cubewebsites replied on at Permalink Reply
No there should only be one core folder.

If you copy the form block controller as described above then it should be sufficient as that controller extends the *core->controllers->mini_formsurvey* controller so you can override the methods you need in that file
nicolechung replied on at Permalink Reply
Ahh I see thanks.

Also I had to disable the "Overrides Cache", looks like there was an identical question here (duh)

http://www.concrete5.org/community/forums/customizing_c5/override-c...
nicolechung replied on at Permalink Reply
I'm getting an error on

if($this->get('surveyName')!='Whatever name you use')


I think it's because $this is the MiniSurvey class, *not* the FormBlock controller class?
cubewebsites replied on at Permalink Reply
Sorry I got it wrong by trying to read the controller file too fast. Basically the MiniSurvey and the Concrete5_Controller_Block_FormMinisurvey are different classes which is why it does't work.

This in fact makes life a bit easier, as you can do the following instead of the previous method:

1) In /models create a new class (call it what you like) e.g. custom_mini_survey.php, do this in that class:

<?php
class CustomMiniSurvey extends Concrete5_Controller_Block_FormMinisurvey {
}

Within that extend the loadSurvey method as needed (no need for the block name checking anymore).

2) Create a custom view template for your form in /blocks/forms/templates
Copy the /concrete/blocks/form/view.php file as a starting point, but make sure you rename it to something else e.g custom_view.php

3) At the top of your custom view, change
$miniSurvey=new MiniSurvey($b);

to
$miniSurvey=new CustomMiniSurvey($b);


4) Set the form to use the Custom View template

This should work (untested but seems logical) and if the custom view doesn't recognise the CustomMiniSurvey class you might have to load it at the top of your view template using Loader::model('custom_mini_survey')
jordanlev replied on at Permalink Reply
jordanlev
You don't say what exactly you want to style, but depending on what it is, this might be helpful to you:
http://www.concrete5.org/marketplace/addons/form-tableless-layout/...
nicolechung replied on at Permalink Reply
I think that's probably it, and I think I've used that addon before (duh).

I keep forgetting how styling the form block is different from the other blocks...is this getting changed at any point?

For the addon, I have one question, can I use more than one custom template?
jordanlev replied on at Permalink Reply
jordanlev
I have no idea what the core team's plans are, but they seem to never go back and clean up existing blocks, so I'd guess "no".

And yes, you can have as many custom templates as you want. Just create more files in the /blocks/form/templates directory (and choose between them by clicking on the block while in edit mode and choosing "Custom Template" from the popup menu.

-Jordan