I am working on a symfony 1.4 project and am trying to add a custom field in a backend form. At the moment, my module has a batch history with editing and deleting options for each row and a form that allows the user to filter through it. I would like to add a custom creation form and I am struggling to do that.
Going on the /*model_name*/new/ page does show me a form: this is the form I would like to make changes to.
I would like to display a dropdown list of elements from another table (and model) on this page. How can I do that knowing that the current module's widgetSchema doesn't have that relation?
Should I edit generator.yml? When I try adding a title: to new: , it doesn't seem to affect the /new/ page (even after cache:clear).
It would be easier if you create that relation in your schema.yml. Your generated form will be able to render the widget you want.
Otherwise, what you need to do is edit the *model_name*Form class by adding the widget and validator you want (sfWidgetFormDoctrineChoice and sfValidatorDoctrineChoice in your case)
The generator.yml uses the form *model_name*Form class by default, but I suggest you copy this class in a lib folder you create in your module, and edit this one instead. Then, you edit your generator.yml to use this new form, this is how you do it
Also, make sure there is not much rows in the table of your relation. Else, symfony will try to generate a html select tag with a lot of options and you will need to kill your php and even webserver processes.
Yes, you need to edit generator.yml, but in the form line:
# apps/backend/modules/whatever/config/generator.yml
config:
...
form:
display:
Whatever...
Here you have some examples. Taken from the official documentation:
http://symfony.com/legacy/doc/jobeet/1_4/en/12?orm=Doctrine#chapter_12_form_views_configuration
This way, the form that the generator uses will be the one you specify. And maybe you don't need to modify something else.
Related
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.
I'm trying to add the editiedon field to the modx manager pages so my users can edit the value using this bit of documentation as a start point:
http://rtfm.modx.com/revolution/2.x/case-studies-and-tutorials/adding-custom-fields-to-manager-forms
Which does work, but:
how can I make that a date/time field?
how can I place it in the settings tab of the given resource?
Isn't input type="date" the answer to the first question? I'm not sure how you would do the second part, unless you managed to get the rendered content and splice it in there somehow (unless theres som hidden specified method).
Otherwise, you could always solve it with regular form customization. You'll want to create a TV of type Date, and give it a custom default data through a snippet, that just fetches the current resources editedon value. I guess you only need to update the resource/update form set. Under the template variables tab of the set, make sure your TV is connected and change the region value of it to "modx-resource-settings"
There are two different ways which have their own pros & cons.
At first you can use template variable with Date type. It gives you correct ExtJS component for dates and you'll see calendar in TV's tab.
If you'll choose this method you have to create a plugin which invokes on OnBeforeDocFormSave event. There you can redefine modResource editedon property from your TV and it will be saved in proper way. Also you may invoke another event(OnLoadWebDocument). There you can set modResource editedon property from you TV if you want to see correct data.
Pros:
fast calendar integration to the one of modResource's tab
you can use Form Customization for security reasons. It's rather easy and from the box.
Cons:
Additional TV which complicates modResource updating process a little bit
Another method is more complicated (you need skills in ExtJS).
Create plugin which invokes on OnDocFormPrerender event. You can add JS to the modResource page there. Your scripts should render new custom tab to the document where you can add your special field with calendar. So there is special ExtJS component in MODX for these purposes. And of course you need events from first method for loading and updating editedon value.
Also you can just render special field to the existing tab instead of creating new tab and rendering your custom field to it.
Pros:
you don't need TV anymore
it's flexible
Cons:
it's more complicated and takes time
P.S. You can view Xlexicon github repo. There you can find example of rendering new tab and manipulation with modResource properties.
Also you can check modAvatar extra for MODX. There is an example of manupulation with existing tab.
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 started creating own Symfony bundles some weeks ago. I've created some entities with all the stuff around (also used the Doctrine CRUD-command), made some twig extensions and created new templates.
Now I wanted to implement a Search Form in my Project. Are there some simlpe ways or some predefined Search-Bundles, which I can use in my Project?
I created my search-form manually (form without an entity). Then form is submitted via GET and the Results (selcted from the Entities in the Controller with a repository-search) are shown below the search form on the same page.
Now I think, that it isn't good to have a very long URL, because of the Fields in the Form. I could go further and submit e.g. a <select> list with multiple entries selected and the URL would even be longer.
Would it be a good choice to submit the Form via POST, "cut" the unnecessary "URL-Array-Elements" (+make the Query-Items more readable for humans) and redirect to the URL with the queries for showing the results?
Edited: Are there any simple ways, how I can create a specific search form or entity-filter which I can use for custom entities? I like to use/create a function, where I can insert the entity, define the search-tags/filters and output a search-form? Has anyone created/used such search/filter-functions?
I have BlocksController and Block model. In cakephp-1.2 I used edit action to edit my application's blocks and it worked fine.
After migration to 1.3 and 2.x I noticed that the edit action leads to saving an edited block as a new record.
In the cakePHP docs I read that in 1.3 the form's helper does not supply the id any more and so the model regarded the process as add.
To solve this issue, I tried to add a hidden field named id with a value of the id of the block is being edited as follows:
<?php echo $this->Form->create('Block', array('class' => 'nice custom'));?>
//The following line is required in cakephp 1.3+
<?php echo $this->Form->hidden('id', array('value' => $block['Block']['id']));?>
The described solution is working fine. However I need to know another way to do that without changing in the view. Does it possible?
TLDR
There are any number of ways to accomplish what you want. The most ideal solution would be to add the id into the view, similar to how you mentioned. But - there are as many options as you can think of.
In View
The easiest (and I would argue the ideal) solution would just be to add the id in your view. You should be able to just add it like this:
echo $this->Form->input('id');
It makes it hidden automatically since it's "id" and it should populate for you as well if you're passing the data correctly to the view.
In Controller
BUT - since your question was how to do it NOT in the view, another option is to do it in the Controller. I don't know your exact project, so change it as you see fit, but before your save, you can always just append the Block's id to the data.
$this->request->data['Block']['id'] = $YOUR_ID;
$this->Block->save($this->request->data);
In Model
This seems like a strange place, but - you if you're storing the ID in session or something, you COULD theoretically add the id here before saving as well.