I want to change the way Drupal builds specific fields on a specific node edit/add form on my site. For example, when I use print drupal_render($form['textarea']); in my node--CONTENTTYPE--form.tpl.php file, I get the default Drupal render of the field widget. I want to modify the HTML markup of the field widget.
There are three ways I can think of that might solve this problem:
Using a forms equivalent of the theme_field() hook. This seems ideal, but after searching for the last few hours, I haven't found anything on this.
Building custom field widgets for every field type I'm using on that node. This is definitely not ideal and I have to believe there's an easy way to do this in Drupal from a theme point of view.
Manually build the HTML markup for the form and field in node--CONTENTTYPE--form.tpl.php with print $form['textarea']['und'][0]['title']; and the like.
Is there a hook in Drupal to do this, or must the code for every field I want to modify be manually generated?
I think the hooks you are looking for are hook_form_alter and hook_form_BASE_FORM_ID_alter. Refer to the Form API to know what you can set on the render array.
Related
i'm using the famous CMB2 to create custom metaboxes, i want to have one hidden field with default value which i will set myself. i used this hidden field type and its working fine , the thing is the metabox will have this field only, so i ended up with what looks like an empty metabox which may confuse the user. i have read dispaly options but this controls where should the metabox appear, i have it exactly where i want on my posts but i want to set it's visability to be hidden so i do not confuse the user , i thought about using css on this but i want to check if there is a way to achieve this using CMB API
i'm adding the css way answer because it works and achieves the requirement , but i would still like to know if there is another php way for educational purpose.
function admin_style() {
wp_enqueue_style('admin-styles', get_template_directory_uri().'/css/admin-css.css');
}
add_action('admin_enqueue_scripts', 'admin_style');
I have been looking for a solution to display custom field tabs in the Joomla
front article edit page.
http://www.aixeena.org/extensions/aixeena-easy-cck
Aixeena Easy CCK
I installed the plugin of aixeena, two custom field tabs: the Extra content and Extra content 2 are displayed in the backend admin article edit page, which is great. But we also need to let regular edit their article and enter values in custom fields under those two tabs. Any idea how to achieve this?
I tried a couple of other sites posting the solution of adding custom fields in article, such as Rating region described in the site:
https://docs.joomla.org/Adding_custom_fields_to_the_article_component
I was not able to make the Rating tab displayed in the front end article edit page neither.
I tried the fieldattach, it does supports custom field tab ( which is the group name of custom field), the list field type only contains static values, we have to define fieldset and field type through xml file.
Any help is greatly appreciated.
I just finished writing a couple pluginsto do this similar thing. I wrote my own plugin to add the extra fields - but it looks like the one you've already used is very similar.
I had a really hard time figuring out how to add the fields for frontend editing as well. But I finally figured it out.
First, you're going to need to copy the com_content form edit.php into a template override (/templates/your_template_name/html/com_content/form/edit.php).
In that file, add the extra fields you have. You'll need the name of the field that you put in the xml file for your plugin you already have. Add them right before/after the fields that are already in the file, that you want your fields to appear before/after. Example:
<!-- CUSTOM begin custom fields -->
<?php echo $this->form->renderField('video_url', 'attribs'); ?>
add all your fields in there - replacing 'video_url' with your own field name. The plugin you already have already saved these fields to the 'attribs' part of the article, so you can leave that there.
The plugin that I used to create the fields for the backend is a really simple one based off of this tutorial https://zunostudios.com/blog/development/203-how-to-add-custom-fields-to-articles-in-joomla
What I'd suggest is to go ahead and create that plugin too. Except in the zfields.php file, change "$app->isAdmin()" to "$app->isSite()" - make sure the xml files have the same names as your other plugin xml files, so they save to the same place, and you're done. The fields will show up on the frontend edit form now.
What I'd really recommend is to get rid of the Aixeena plugin, and just make that easy plugin using the tutorial above - it's super easy. When you make it, duplicate the "if ($app->isAdmin())" section, copy it right below it, and change "isAdmin" to "isSite" - and now you've got the entire thing, all your custom fields, both frontend and backend, all in one place. Now just do the edit.php template override, and you'll have them displayed in both the front and backend. I hope that helps - if you need I can upload more example code.
Introduction:
I'm using wordpress theme called ClassiPress I'm very familiar with custom fields and how to use and display them.
In that theme you have ability to create custom fields and than display them for normal users when they are publishing an advertisement (it's cassified ads theme).
Problem:
I want to display custom field in which would be displayed html content in this case table which people would fill up with information and later i would display that table in their post .
( sentence in bold text means that i know how to do that part.)
Note: I know that by doing this i even risk to get xss holes.
Question:
Is it possible to display custom field with html content in it? Int his case it would be simple html table.
What i have tried:
Well since I'm not sure even hfrom what to start i have tried really cheezy and maybe even funny method i have created custom field as text area and went to mysql found that custom field and tried put content in that field in this case just simple <b>It Works</b> code to see if that would display bolded text in that text area. But it didn't work maybe becausein database there wasnt right tab;le for it or i did something wrong.
Additional Information:
Please also note that in that theme which has custom fields they are limited that means i can't create things that allowed in other custom fields plugins. Pleas etake a look at picture bellow which custom fields tylpes it supports:
Please click here in order to see image
I would be very thankfull to person which would provide me any solution it could be alternative way but overal would do the idea that i want which i hope i have explained well.
None of those form elements allow raw HTML. If you are going to put HTML in an input field or textarea, it will need to be HTML-encoded. For example:
<b>It Works</b>
would need to be:
<b>It Works</b>
There are various ways to do that, but it might be hard to make it user-friendly.
I would like to be able to use multiple form field widgets for the same field and to be able to switch it based on session data from the user. But I am not really sure how to accomplish this. This is for Drupal 6. Any ideas on how to accomplish this?
You might be able to accomplish this with one of the field access modules but to do it properly you'd probably need to create a custom widget. Your widgets can return existing widgets by calling their handles, so your widget would more or less be a wrapper that returns the correct widget call.
this tutorial gives a pretty good overview of widget creation in Drupal 6.
What I ended up doing was creating a second form field that uses the filefield upload widget and loaded it on the form alongside the Flash widget. Then I put JS on the page that detects if Flash is on the page and is of the correct version. If it is found then it hides the html/AJAX uploader. If it is not then it hides the Flash uploader.
I was just wondering if there was a super quick way to automatically add a filtering system into Drupal views.
I.e. I just need to add in the top of my view search by name (text box) and search by category (drop down box)
Or do I just manually create this form then use the filter agruments within the edit view screen?
I found the answer.
It's part of the Views Module under filters - then you just expose them, simple...
Not sure what Daniel was on about?
I dont understand exactly you question, but have you tryed VBO?
However, when you create a view you can 'expose' the filters you use, so the user can change it in the view page.