Create the tx_news searchform in the layout - typo3

I would like to create the tx_news searchform on every page. So I try it to put it into the Layout:
<div class="news-search-form">
<f:form object="{search}" name="search" pageUid="{settings.searchPid}">
<fieldset>
<f:form.textfield id="news-subject" property="subject" class="form-control"/>
<f:form.submit class="btn btn-default search-button"/>
</fieldset>
</f:form>
</div>
The problem is, that {search} is not defined when there is no searchplugin on the site.
When there is a searchplugin {search} looks like this:
Tx_News_Domain_Model_Dto_Search (prototype transient entity)
subject => NULL
fields => NULL
uid => NULL
_localizedUid => NULL
_languageUid => NULL
pid => NULL
Am I somehow able to create this directly in the layout or what would be the best way to have the searchform on every page?

You can use direct TS easy
lib.blogsearch = USER
lib.blogsearch{
userFunc = tx_extbase_core_bootstrap->run
extensionName = News
pluginName = Pi1
switchableControllerActions {
News {
1 = searchform
}
}
settings < plugin.tx_news.settings
settings {
listPid = #you_id
}
}

Have you tried to insert the searchform via typoscript as records?
To do this, you should create the news plugin configured to search form somewhere in your pagetree, and reference it via ts like this:
lib.searchform = RECORDS
lib.searchform {
wrap = (whatever)|
tables = tt_content
source = {id of the searchform CE}
}
This should do the trick.

Related

TYPO3 Extension in Typoscript COA does not recognize Default Controller

I am trying to override a Marker within my Typoscript with content rendered by my custom created extension.
As far as I know It should work like this (Where MENU_PRODUKT_CATEGORIES) is my Marker:
MENU_PRODUKT_CATEGORIES = COA
MENU_PRODUKT_CATEGORIES {
10 = USER
10 {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
extensionName = MoTimeProducts
pluginName = Products
vendorName = products
controller = Category
action = parentList
}
}
The extensionName and related configurations also seem correct to me. When I var_dump() my ext_localconf.php configuratin this is displayed:
My first Parameter where MoTimeProducts is my extensionName and products my vendorName. Is this correct?
MoTimeProducts.products
The second Parameter should be the pluginName and seems ok, too.
Products
This is how my complete ext_localconf configuration looks like:
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'MoTimeProducts.' . $_EXTKEY,
'Products',
array(
'Category' => 'list, parentList',
'Product' => 'list, show, filter, ajaxFilter, refList',
'Formular' => 'display'
),
// non-cacheable actions
array(
'Category' => '',
'Product' => 'ajaxFilter, list',
'Formular' => 'display'
)
);
My Controller and Action configuration seems fine also. Below my action within the CategoryController
/**
* action list
*
* #return void
*/
public function parentListAction() {
$this->view->assign('categories', $currentCategory = $this->categoryRepository->getHighestLevelCategories($GLOBALS['TSFE']->sys_language_uid));
}
I also have a flex form for the Backend configuration and inserting plugins could this also be a reason?
Thx for reading.
Oh wow it was
MENU_PRODUKT_CATEGORIES = COA
MENU_PRODUKT_CATEGORIES {
10 = USER
10 {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
pluginName = Products
extensionName = Products
vendorName = MoTimeProducts
controller = Category
action = list
switchableControllerActions {
Category {
1 = parentList
}
}
}
}
Where vendorName with a combination of lowercased plugin name is the first paramater for the plugin configuration.
Edit: Turns out it is very bad practice to have the same name for the plugin/extension which can lead to confusion and errors. One should avoid doing it like I did at all cost!

How to make checkbox checked based on the data from database in mvc 4 entity framework?

I am strong checkbox checked data in db. If the checkbox was checked i want to display it as checked in view. Is it possible to achieve this?
Here is my supporting code.
public ActionResult Index()
{
var groups = db.tm_grp_group.Where(a=>a.grp_isactive==true);
var permissions = db.tm_perm_level;
GroupPermissionVM model = new GroupPermissionVM
{
GroupList = new SelectList(groups, "grp_id", "grp_name"),
Permissions = permissions.Select(p => new PermissionVM
{
perm_id = p.perm_id,
perm_levelname = p.perm_levelname
})
};
return View(model);
}
This is index.cshtml
#model Permission.Models.GroupPermissionVM
#{
ViewBag.Title = "Index";
}
<h2>Index</h2>
#using (Html.BeginForm())
{
#Html.LabelFor(m=>m.GroupID)
#Html.DropDownListFor(m => m.GroupID, Model.GroupList, "Please select", new { id = "ddlgrp" })
#Html.EditorFor(m => m.Permissions)
<p><input type="submit" value="Submit" /></p>
}
Inside Home/Editortemplate/PermissionVM.cshtml
#model Permission.Models.PermissionVM
#{
ViewBag.Title = "PermissionVM";
}
<div>
#Html.HiddenFor(m => m.perm_id)
#Html.HiddenFor(m => m.perm_description)
#Html.CheckBoxFor(m => m.perm_status)
#Html.LabelFor(m => m.perm_status,Model.perm_levelname)
</div>
I have table structure like this
grp_id perm_id
1 1 1
2 2 2
permlevel_name perm_status
1 Screen Level True
2 custom Level True
Grp_id is dropdownlistbox in this context. So if i select 1 corresponding permlevel_name is screen level and it is checked. So when i make selection as 1 below screenlevel checkbox should be cheked. Is it possible to achieve this?
in your code where you call PermissionVM.cshtml File.

WWW::Mechanize::Firefox put content into input by id

I am using WWW::Mechanize::Firefox. How to put content into input by id and after that to press link witch, using JS, submit page?
<input id="my_input" type="text" class="some_class"/>
<a id="send_with_me" href="#">Press me</a>
How to do it?
Thanks
Answer to request of Borodin:
my $mech = WWW::Mechanize::Firefox->new(
activate => 1
);
my $content = $mech->get("http://some_url.com");
$mech->field(".my_select_element_by_class", 1); #select element from select by class
I want to put value into input by id. Something like this:
$mech->field("#my_input", 100);
$mech->some_method_witch_press_href("#send_with_me");
You need this to click the link (by CSS selector):
$mech->field("#my_input", 100);
$mech->click({ selector => '#some_id' });

How to wrap radio button group in label zend form

I want the following html with two radio button groups in zend form
<label class="inline">
<input type="radio" name="form-field-radio">
<span class="lbl"> Male</span>
</label>
<label class="inline">
<input type="radio" name="form-field-radio">
<span class="lbl"> Female</span>
</label>
and i'm using the following code to make this button in Zend Form
$gender = $this->CreateElement('radio','gender')
->addFilter(new Zend_Filter_StringTrim())
->setMultiOptions(array('M'=>'Male', 'F'=>'Female'))
->setDecorators(array( array('ViewHelper') ));
But I don't know where to set the lable and span classes in this code.
Please help.
Thanks.
I am not sure whether its the perfect method to do this its the first time i am using zend framework, But still here are the steps that i did, if you may find useful:
First I created a custom decorator which extends Zend_Form_Decorator_Abstract and saved it in the location 'decorator/My_Form_Decorator.php'. decorator is a directory created by me in root.
.
/decorator
/application
etc...
Then i included it in a controller. I have read that there are certain methods for adding the decorator like addPrefixPath() but for time sake i just included the decorator file in top with 'include "../decorator/My_Form_Decorator.php";'. Then instead of using the CreateElement method i used Zend_Form_Element.
The following is the code of custom radio decorator
My_Form_Decorator.php
class My_Decorator_RadioInput extends Zend_Form_Decorator_Abstract
{
public function render($content)
{
$element = $this->getElement();
$label = htmlentities($element->getLabel());
$type = $element->type;
$name = $element->elemName;
$multiOptions = $element->multiOptions;
$labelClass = $element->labelClass;
$spanClass = $element->spanClass;
$markup='';
if(!empty($type) && !empty($name) && !empty($multiOptions) && is_array($multiOptions)){
foreach($multiOptions as $key=>$value){
$markup .='<label class="'.$labelClass.'"><input type="radio" name="'.$name.'" value="'.$key.'"> <span class="'.$spanClass.'">'.$value.'</span></label>';
}
}
return $markup;
}
}
and this is the code in my controller function
IndexController.php
$decorator = new My_Decorator_RadioInput();
$form = new Zend_Form();
$form->setAttrib('id', 'test');
$element = new Zend_Form_Element('foo', array(
'elemName'=>'gender',
'type' =>'radio',
'multiOptions' => array('M'=>'Male', 'F'=>'Female'),
'labelClass'=>'inline',
'spanClass'=>'lbl',
'decorators' => array($decorator),
));
$form->addElement($element);
$this->view->form = $form;
And in view index.phtml
echo $this->form
Hope this is helpful to you..

Codeigniter: getting select option from form

I'm trying to get the option item selected in a form select element using Codeigniter...
I have a controller named results with this code in it
//get form data
if($_SERVER['REQUEST_METHOD'] == "POST"){
$data['searchdata'] = array(
"ionum" => $this->input->post('ionum'),
"thisdb" => $this->input->post('thisdb')
);
}
which loads into a view, the 'ionum' is a text input which I can retrieve, the 'thisdb' is the select, I get no results for it...how do I pull that?
Ensure your html looks like:
<form action="<?= site_url('mycontroller/myfunction');?>" method='post'>
<input type='text' name='ionum'/>
<select name='thisdb'>
<option value='db1'>DB1</option>
<option value='db2'>DB2</option>
</select>
</form>
Then in your controller, you would write:
class Mycontroller extends CI_Controller{
function myfunction(){
$p = $this->input->post();
if($p){
//you can now access the ionum and thisdb... try echo
echo $p['ionum'];
echo $p['thisdb'];
}
}
}
It is unnecessary to run the if($_SERVER['REQUEST_METHOD'] == "POST") conditional. Just check if $p exists as above.