Ok so i tried using zend form but what i'm trying to accomplish is way too much for me to handle zend form. I'll try to describe it in a few lines maybe you have a solution for me if not you will understand why i chose to use a form in a view file.
I have a form for searching products in a database. THe search is done using autocomplete (custom made). When the user presses "Add product to list" the product is being added to a div in the form, creating the impression of a list. I want to submit this (the newly added inputs in the form) to the controller and process the form. I don't know how to do this, or it is not possible, have no clue yet but the zend form gave me so many headaches that i am very close to stop using it.
So i have designed a static form, in my view file. I have my jquery stuff there, i add data (hidden input fields and checkboxes) and i want to post to my controller. The question is how do i get the $_POST array in my controller?
I'll try to answer you as better as I can givin how your question is vague.
If you have a html form on your webpage all you need to do is set its action to your controller:
action="mycontroller/myaction"
And in case its not:
method="post"
And in your controller in fact this would work:
$_POST['param_name']
but the Zend way would be in your controller's action:
if ($this->_request->isPost()) {
$data = $this->_request->getPost();
Zend_Debug::dump($data);
}
Hope this help. If you need more details edit your question to make ti more clear.
Also it does'nt matter if the form was created with Zend_Form or by hand that code will work regardless.
Related
When we develop forms for CMS (for example an Add product page and a edit product page), we usually develop 2 pages. But this result in double work and harder in maintenance & amendment.
Is there any way that I can do a form to be reusable on both add / edit page with Laravel?
Thank you.
Yes, provided that your add/edit form is identical. Here's a brief idea on how it can be done:
Load the form using Form::model binding (http://laravel.com/docs/html#form-model-binding) which will populate the HTML fields with current values (for editing) or empty (for new form)
Add a hidden field in your form, like the product_id which is either loaded or generated depending on whether it is an edit/new form
Upon submission to your controllers you can use something like this:
//after form validation
$new = Product::firstorCreate(array(
'product_id' => Input::get('product_id')
));
//assign the rest of the fields
$new->save();
I hope that can give you an idea to solve your issue.
I use more obvious approach:
Former could be used both in views and controllers, so I use it in controller
I create simple private method that holds my form
Use it both in add and edit action
I'm trying to create a custom Jtoolbar button in Joomla 2.5. I'd like the button to act very similar to the built in edit button, except I'd like it to be called generate. The button should load a generate view (similar to the singular edit view). It should have form fields for the user to fill out and then click a submit/save button that will run a php module to populate the database with calculated values.
My google searching has been very unproductive. So far I've been able to create the button with in games/view.html.php:
JToolBarHelper::custom('games.generate','extension', 'extension', 'generate', false);
I believe this should call a controller method in controller/games.php called generate().
in controller/games.php:
public function generate()
{
JRequest::setVar('view', 'schedule');
Jcontroller::display();
}
After much muddling around, this appears to be loading the view and a template tmpl/default.php. This seems wrong, but it's the furthest I've gotten so I'm going to keep going with it until I get it all figured out.
Original Question:
How do I get that controller to load the view/form/fields/template and then run the php script to populate the database. I probably just need a point in the right direction to figure this out. There doesn't seem to be any complete tutorials/examples on adding a custom button.
A couple of years old, and it's for 3.2, but I added this to my controller for a custom view. I needed a layout called insert. I don't know why you couldn't do the same to just change the view.
public function insert()
{
$this->setRedirect(JRoute::_('index.php?option=com_mycomponent&view=date&layout=insert', false));
}
Calling it the same way from a custom Jtoolbar button. It works, but maybe there is still a better way.
I am struggling to find out if I can do this but I have a cakephp form with many input fields and when submitted I write them to a text file I can add fields in dynamically here by clicking a button but:
My question is if I have an admin page how do I get that to dynamically add fields to the page and make them stay there forever not just for that session?
Really stuck figuring out how to do this any guidance would be much appreciated.
Thanks in advance.
Make them persistent. You need to store the form and the fields it has: "Form hasMany FormField". The fields should describe a type so that the FormHelper will render the correct inputs.
When you want to display the form read that information from the db again and render the form according to your stored information.
I am guessing you already have a javascript function that dynamically adds the field to your admin page. Is that correct?
I don't use CakePHP, but a general workaround I use is to use the javascript function to at the same time update a table in the database that stores the form layout.
Here are some Jquery Form builder plugins that you can use to achieve the goal.
http://www.berthou.com/us/2009/09/05/dynamic-forms-builder-with-jquery/
https://github.com/botskonet/jquery.formbuilder
http://code.google.com/p/jquery-form-builder-plugin/
http://www.elizaibeth.com/2010/11/23/dynamic-jquery-form-builders/
Here is an excellent link of PHP FormBuilder class with tutorial, that you can use as a vendor library into CakePHP.
I am trying to do something really basic but can not seem to find a tutorial for it.
I have created a simple web form using HTML what I need todo is create a php file that will read the web form, open a new browser window (or display in same page) the contents of the web form, do toy guys have any tutorials on this?
Many thanks
Chris
I'm sure many will post different links to tutorials that they like, but I thought I would just give you the basic. The key parts to the form are the method and action. The Method attribute tells ths browser how to submit the data, either through GET or POST. The action attribute tells the browser where to submit the form. (In your case it will be, somepage.php) If you ever need the form to submit back to itself, you can here use explicitly type the page name or you can use use PHP to dynamically insert the page name. Finally, make sure that all your form fields use the name attribute, as this is how php will access the elements.
On the php side of things, your form variables will be stored in either $_GET or $_POST depending on how on method you used to submit your form. For example, assume you have a input element of type text with the name 'FirstName'. Within php you can access this by doing
<?php
var firstName = $_GET['FirstName'];
?>
This should be enough to get you started. Be sure to check out the php docs and the other tutorials listed on this page for a more details.
Please look at this tutorial: http://www.learnphp-tutorial.com/HtmlForms.cfm
And you can find many more tutorials if you search it on Google.
This should help : http://www.php-mysql-tutorial.com/wikis/php-tutorial/php-forms.aspx
i am new to cakephp, and also new to ajax.
the function i trying to do is basically like this:
i am in a add page, which let me select few customer on that page.
but i wanted to set 1 more link for user, which let user click customer immediately on the add page, and the new data will show in my add page without refresh, so that the user can choose the new added customer for enter my form.
i know the idea is base on using ajax. but i am still new to it and hope any 1 can give some comment or suggestion how can i start??
the problem i face is, i am on a form, when i adding a new customer in the form, i wanted to get the new customer to show in my form without refresh. what can i do for getting this function?
thanks a lot and i will very appreciate your answer.
CakePHP has an ajax helper, which requires the prototype library. You can find the API for the AJAX helper here:
http://api.cakephp.org/class/ajax-helper
And a guide to using the helper here:
http://book.cakephp.org/view/208/AJAX
And a list of cakephp/ajax articles here:
http://bakery.cakephp.org/articles/search/tags/ajax
It's beyond the scope of a Stack Overflow answer to give you a tutorial but hopefully these links will help.
easiest way is to use a javascript library (like jquery for instance) to do an ajax request.
probably to a controller/action in your cake framework.
the easiest way would probably be returning the data in JSON and filling out your form fields.
PHP Json
jQuery AjAX/JSON