Adding input fields to a cakephp form through admin - php

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.

Related

build dynamic field in form symfony

I'm asking you for a little advice on creating a specific form in Symfony3.
I need to create a form that upload's an unspecified number of files, which every file has a description text input that belongs to that file.
That's the doc you're looking for https://symfony.com/doc/current/reference/forms/types/collection.html
Come back for more details later :)

SilverStripe form pagination

I am using a form on a SilverStripe page, the form is currently quite long. I am looking for a way where I can paginate the form. I would like to have 5 fields showing. Once them fields are filled out the user could then click next and be shown the next 5 fields. Also a previous button would be required. Thanks for your help if you need any more info let me know.
You probably want to look into the multi-step-form module : "MultiForm is a SilverStripe module, allowing flow control for forms, and step process to be automatically determined based on configuration variables on each step class. It augments the existing Form class in SilverStripe."
I believe this allows you to do what you need. The github repository has a complete example to set up and I recommend reading it in detail.

Laravel 4: Reusable Forms (Add / Edit page)

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

Creating a custom Jquery modal form to upload data

i am new to jquery.I looked to various demos but can't find what i am looking for.
I have a button.I want to add a functionality in which button Onclick would open a modal form through which a user can upload various details about a particular item like it's name,size,colour,brand,cost,images,description.
After filling the details these various fields will be stored in a mysql database using a php file.
I want to make this custom dialog form on the same principle as the form on jquery website.
http://jqueryui.com/dialog/#modal-form
I tried making a custom dialog form using the example in the above hyperlink but not being able to create one..
Please help.
The example on the page you linked is created by using jQuery UI, if you click the "view source" link on the page, it will show you how to do it (how it is created in their page).
I would suggest, though, to use a modal that would be easier to implement for a new user, fancybox, for example as it has clear examples on how to implement on their site and it will get you up and running much faster.
you have to use the UI pack for this , else you can do this by creating j query simple calls
1. onclick show form
2. on save send a ajax call
3.after saving record the function you have generated to fetch records from db call it, it will display the updated record from db.
i personally suggest you to make it your self for better understanding for work its just simple and easy
if you use UI then you have to make changes to it for as your requirement and that's also too easy.

zend get posted variables from static form from the view file

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.

Categories