I need some help with converting SS3 to SS4. I would like to render my contact form on another page as well as my default Contact page. I managed to get it working in SS3 but things are a little different in SS4 and I am not sure how to write the function or where to put it. I have tried a bunch of combinations and locations but I need help.
In SS3 I created my UserDefineForm page with its fields. I then added the following to the custom page that I wanted the form to render too:
class IndexPage_Controller extends Page_Controller {
// Sign up form
public function SignupForm(){
$get = DataObject::get_one('SiteTree', "URLSegment = 'contact-me'");
return new UserDefinedForm_Controller($get);
}
}
What/Where do I put the function in SS4 to get the form fields to render on the custom page template as it does on the Contact us page?
Thank you in advance.
The code below should work.
public function getSignupForm()
{
$page = \SilverStripe\UserForms\Model\UserDefinedForm::get()->filter('URLSegment', 'contact-me')->first();
$controller = \SilverStripe\UserForms\Control\UserDefinedFormController::create($page);
return $controller->Form();
}
Related
I'm posting this after my hair has been ripped out, ran out of rum, and tried everything I can find on google. I've been developing a site using codeigniter which makes use of templates. I've built the backend first and all is working properly there. So now i've started on getting the front end working which is where I'm hitting the issue.
I've created a controller called pages.php which is going to parse the uri string of the current page, use my library to get the page data from the database, then display it. My pages are all created through an editor on the back end and stored in the database.
So here's the pages controller
class Pages extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library("pages");
}
public function display_page()
{
$page_slug = $this->uri->segment(1);
$data["joes"] = "Here's joes first variable";
$this->pages->get_page($page_slug);
}
}
and here's the error message i get when i hit my url like this demo.mydomain.com/joes-test
and here is how my routes are set up. $route['(:any)'] = 'pages/display_page';
My Pages.php library works perfect on the back end but it's a large file. I've only posted the get_page function below. If you need to see everything let me know. But i dont believe the issue has anything to do with the library itself.
public function get_page($slug){
$objPages = new pages();
$objPages->get_object('slug="'.$slug.'"');
return $objPages;
}
[EDIT] If i place the following inside my homepage controller it works. But the calling function needs to be inside the library.
$this->load->library('pages');
$the_page = $this->pages->get_page("joes-test");
I want to call $this->get_object("joes-test") but this doesn't work. get_object() is an inherited function inside the library.
Now oddly enough. The code i put above will NOT work if i do the exact same thing inside the pages controller
any help leading to a solution would be awesome. I'm under a time crunch and pay to get some assistance. Thanks in advance.
No you can't use the same name with controller and library. please choose another name. for example Mypages for you controller name.
change your routes
$route['(:any)'] = 'mypages/display_page';
then call your controller.
http://demo.mydomain.com/joes-test
I think there nothing wrong with library uri, because as codeigniter official website say: This class is initialized automatically by the system so there is no need to do it manually.
I don't know about lib pages, but how about use
$this->load->view(<file-html>);
and if you want to passing data in variable, you can add variable like this
$this->load->view(<file-html>, $data);
Hope this help, Cheers
I'm using Silverstripe FullTextSearch. My interrogation is how search in a custom field and show results. There is code write in index.md :
File: mysite/code/MyIndex.php:
<?php
class MyIndex extends SolrIndex {
function init() {
$this->addClass('MyPage');
$this->addFulltextField('Description');
}
}
In Page.php
class Page_Controller extends ContentController {
private static $allowed_actions = array('search');
public function search($request) {
$query = new SearchQuery();
$query->search($request->getVar('q'));
return $this->renderWith('array(
'SearchResult' => singleton('MyIndex')->search($query)
));
}
}
When I'm trying to search some words from description field, no results are found... Suggestions?
In my experience FullTextSearch has been frustrating and problematic. I am willing to be corrected, but I feel like the devs are moving away from it in place of using SearchFilters (https://docs.silverstripe.org/en/3.1/developer_guides/model/searchfilters/).
If it is helpful at all I wrote a module that allows for custom searching and displaying the results in a custom controller. It isn't as efficient as FullTextSearch but works pretty well (https://github.com/i-lateral/silverstripe-searchable).
I did originally try to write this module using FullTextSearch, but I just couldn't get it working.
Well, I have found a solution. FullTextsearch module always search in $Title, $MenuTitle and $Content. Instead of using $Content for my content, I use $ContentPage variable. All DataObjects and other variables must must added like bellow.
Example :
$this->Content = $this->ContentPage." ".$this->Variable1." ".$this->Variable2." ".$dataobject;
In the example, all variables and dataobject in the page is searchable throught $Content. That's not a perfect solution, but works.
In SilverStripe how do you display two UserDefinedForms on one page?
I can display one UserDefinedForm on a page, but I am unable to display two on the same page. I would like to display two UserDefinedForms on my home page.
To display one UserDefinedForm I put this in my HomePage template:
<div id="contactForm" style="display: none;">
<% control ShowForm %>
<p><strong>$SiteConfig.FormHeading</strong></p>
$Form
<% end_control %>
</div>
Function ShowForm() is in my HomePage.php
function ShowForm() {
$get = DataObject::get_one('UserDefinedForm');
return new UserDefinedForm_Controller($get);
}
My problem is that I have created two forms, one is for contacts and one is for booking test drive. Both forms are UserDefinedForms, so if I write another function in HomePage.php example:
function ShowTestDriveForm(){
$get = DataObject::get_one('UserDefinedForm');
return new UserDefinedForm_Controller($get);
}
it will do nothing, or will render my first contacts form.
If I have created two UserDefinedForms what should the php for test drive form look like?
I tried to get it by URLSegment, but it gives me an internal server error:
public function showTestDriveForm() {
$record = DataObject::get_one("UserDefinedForm", "URLSegment = 'BookTestDrive'");
$results = new UserDefinedForm_Controller($record);
return $results;
}
How do I get the second UserDefinedForm to the homepage template?
You have a general misunderstanding on DataObjects, Pages & Controllers.
UserDefinedForm page type holds a form construction. They are pages, not separate objects (one does not query forms directly). The controller is the part that handles a request and contains an actual form handler.
You have also not specified a version, so I will assume SilverStripe v3.1
The basic thing you're looking for is:
public function ContactForm() {
return ModelAsController::controller_for($this->ContactPage())->Form();
}
public function TestDriveForm() {
return ModelAsController::controller_for($this->TestDrivePage())->Form();
}
Possibly with a bit more error checking.
This code also makes the assumption that your homepage has two has_one relations to UserDefinedForm pages named ContactPage and TestDrivePage.
I am creating custom admin module where grid, edit, new, delete work as same as product grid. Everything working fine but when i click on grid row to edit item it redirects correctly but the all pages value is blank.
If you need any page please ask me here i can post the pages here
Normally in edit pages there is a form container, which contains a form, which has a method something like this:
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$fieldset = $form->addFieldset(/* ...stuff... */);
$fieldset->addField(/* ...much more stuff... */);
$form->setUseContainer(true);
$this->setForm($form);
}
Without seeing any code I cannot guess what you have named things but at some point after adding fields you must also do:
$model = Mage::registry('some model you registered in a controller');
$form->setValues($model);
I am trying to add the view action to my back office module page but i cannot display anything with the renderview() function. I can already display my list with renderList() and it's working well. I also tried renderForm() and it works well too but it seemz i can't get renderView() to display something.
public function renderView(){
if(!($config = $this->loadObject())){
return;
}
$data = Config::getDataForm(Tools::getValue('id_config'));
// var_dump($data);
$this->tpl_view_vars = array(
'id_config' => $data['id_config'],
'prix' => $data['prix'],
'hauteur' => $data['hauteur_passage']
);
return parent::renderView();
}
This is a pretty basic code. My getDataForm($id_config) is getting fields from database in an array so that i can display it. I can see the var_dump displaying for a short time before displaying the blank page with prestashop header and footer. I tried to see if i was doing something wrond by checking other AdminController such as AdminCartsController or AdminCustomersController but it seems that their renderView() function is more or less written the same way.
Thanks in advance for your help !
I manage to resolve this problem simply by adding a view tpl in /modules/mymodule/views/templates/admin/mymodule/helpers/view/.
I wrongly assumed that it didn't need to create a template file for the view action as it didn't need one for the list and form action. After searching through modules and admin files i managed to find that there were indeed a custom view.tpl for the view action.
The renderview() method lets you set up the variables you want to use in your view.tpl.
For more information on how it works, you can check AdminCustomersController to see how it is on the controller side and /adminxxxx/themes/default/template/controllers/customers/helpers/view/view.tpl to see how the template is written.
Feel free to edit or comment if you need more information
If you want to add a configuration page on your module, you'll have to add this function to your module :
public function getContent()
{
// return some html content
}
If you want to use a controller, then you'll have to create a Controller that extends ModuleAdminController and add it in the tabs of the back-office.