I have search panel(basic form with keyword), now I need to show this form on all pages, how could I do that? If I create action in controller and render
{{ render(controller('WebPortalBundle:Default:searchForm')) }}
in ::base.html.twig, form doesn't submit anything.
Could someone advise me with this issue?
Symfony create a sub-request for it. You should to pass master request object to this action and use it to handle form:
{{ render(controller('WebPortalBundle:Default:searchForm', {request: app.request})) }}
and in controller do something like:
class DefaultController extends Controller
{
public function searchFormAction(Request $request)
{
// other code...
$form->handleRequest($request);
}
}
Related
Iam using zend_Form for creating forms in my project
The form titles are wrapped by 'h2' tag in default.
How can i change it to 'h3' tag,so that particular form title will wrapped by 'h3' tag.
Following is my code
class Core_Form_Contact extends Zend_Form
{
public function init()
{
$this->setTitle('Contact Us');
}
}
Any one have idea?
I'm using extbase, fluid system on typo3 to build a backend module.
I Have a Controller "MainController" action called 'AddBoxes' and I have another Controller called BoxElementsController, and there is an action method called 'popupBoxAction'.
I want to render the output of the BoxElementsController->popupBoxAction in the MainController-AddBoxesAction();
so that I can assign the output to my view variable.
How can i achieve this in Typo3 6.1.
Thanks
Also you can fetch data or output whatever you like from BoxElementsRepository
class MainController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
protected $boxElementsRepository;
public function injectBoxElementsRepository(BoxElementsRepository $boxElementsRepository) {
$this->boxElementsRepository = $boxElementsRepository;
}
public function AddBoxesAction(){
$popupBoxActionOutput = $this->boxElementsRepository->popupBox();
$addBoxesAction = $this->mainRepository->findAll();
$this->view->assignMultiple(array(
'popupBoxActionOutput' => $popupBoxActionOutput,
'addBoxesAction' => $addBoxesAction,
));
}
}
Try to instantiate you controller in you action then call ControllerObject->initializeAction() before calling your desired action.
Is it possible to load a Zend_Form from a view helper? I'm using thise form in a login action method. But I also want this form to be visible on the navigation on every page (so without the login action actually being called yet), the post method of the form will send to the login action method.
I'm guessing it should be done with a view helper but I don't see how.
Any ideas?
I tried with this:
my view helper:
class Zend_View_Helper_LoginForm
{
function getLoginForm(){
$form = new Form_LoginForm();
return $form;
}
}
and I call it from my layout like this:
<?php echo $this->form(); ?> but this doesn't work. (I'm able to call the same form through an action method though!)
In this case it gives me this error (which doesn't make sense because my helper is only 9 lines long):
Warning: Missing argument 1 for Zend_View_Helper_Form::form() in C:\xampplite\htdocs\zendpr\library\Zend\View\Helper\Form.php on line 44
Your view helper should extends the Zend_View_Helper_Abstract class and the method of the view helper must have the same name as the class :
class Zend_View_Helper_LoginForm extends Zend_View_Helper_Abstract
{
function loginForm() {
$form = new Form_LoginForm();
return $form;
}
}
and you call it like this in your view script :
echo $this->loginForm();
If you call :
echo $this->form();
You are using the view helper Zend_View_Helper_Form
Have your View_Helper extend Zend_View_Helper_Abstract and override the setView()
class Zend_View_Helper_XX extends Zend_View_Helper_Abstract {
public $view;
public function setView(Zend_View_Interface $view)
{
$this->view = $view;
}
Initialise the form in your controller action and set the form reference
// controller action code
$this->view->form = $form;
Then in the view helper you can reference the form via the view
// view helper code
$this->view->form;
class Zend_View_Helper_LoginForm extents Zend_Form {
function getLoginForm(){
$form = new Form_LoginForm();
return $form;
}
}
OR
$this->view->form=$form;
Both are going to return the form. The view form is more specific for view.
Add this into your phtml view file
echo $this->form();
To answer this question - Remove the Parenthetical
Should be
echo $this->form;
I have a masterpage that render's the following PartialView:
<% Html.RenderPartial("AddPage); %>
AddPage Controller looks like this:
public class PagController : Controller
{
[HttpGet]
public PartialViewResult AddPage()
{
return PartialView();
}
[HttpPost]
public PartialViewResult AddPage(FormCollection forms)
{
//some logic here
// some view data here
return PartialView();
}
}
And the view looks like this:
<% using (Html.BeginForm("AddPage", "Page", FormMethod.Post, new { ID = "PageManager" })){%>
<%= Html.TextBox("txtAddPage") %>
<input type="submit" value="AddPage" />
<%} %>
My issue is, that when i hit submit i get redirect to : http://localhost:1234/Page/AddPage, when instead i just want the partialview to be submitted, and return some basic view data if needed, as well as stay on the same page.
Am i having a blonde moment here? cause i know i have done this before
EDIT - This partial view is rendered in multiple pages, not just one.
Fullpage postback solution
This is a bit tricky since you have to know where to go back. I suggest you change your view and add two additional hidden fields (or one and parse its value - as you wish) and store current controller/action values in it.
You can then use this data in POST action to return a RedirectResult like:
return RedirectToAction("action_from_field", "controller_from_field");
Ajax postback solution
You can always submit your data using Ajax in which case your postback URL can be anything you want. In your case it should be to the current page URL. Edit: And Ajax would be the preferred solution in your particular case.
If you want to submit and only reload part of your page, you'll need to use AJAX. The most basic way to do this would be to render the partial view in an UpdatePanel.
i have a custom helper written which returns the html form as string which extends the Zend_view-hepler_Abstract
Now i have 3 helpers .How do i assign each helper to a different view .
It is something like this in the controller
class abc extends Zend_controller_front{
public action page1Action (){
// I want to use a different Helper
//How do i assign custom1 helper to this view Separately
}
public action page2Action (){
// I want to use a different Helper
//How do i assign custom2 helper to this view Separately
}
public action page3Action (){
// I want to use a different Helper
//How do i assign custom3 helper to this view Separately
}
}
um, should you be inheriting from Zend_Controller_Action not Zend_Controller_Front?
also the word 'action' is not a valid php keyword?
just use the view helper in your view script, so in abc/page1.phtml
print $this->page1Helper()
similarly for page2 and page3
but there may be an easier way... you can just
print $this->form;
and the form will print without the need for a helper?