I've been searching for quite a while now and still wasn't able to find an answer yet.
I'm using Drupal 7.4 and I created a new content type. There i want to add a simple text field that has a Default value where I can add PHP. Normally, the Default value shows only plain text.
To be more specific:
For the users I defined a field_city that they must complete when they sign up.
So for example i would have a user "john" from "Bucharest".
I need to assign the value of field_city - namely Bucharest - to the default value of the text field via PHP (I know how to do this part).
So when john adds new content, he would already have Bucharest printed in that text field but still be able to write whatever other city there.
How could I achieve this?
Can I get away without making a custom module?
Thanx.
Are you using the CCK module for Drupal 7? Although it is still in development status, it will do the trick.
Related
I have a website with more than 15 ACF groups. On one of them, there's a repeater and the last of 6 fields is a URL (I tried switching it to Text, same result). I see the field on my page where I use it as a block (Gutenberg). I can enter a value, and it "saves"... Or so I think. If I refresh the page, it's not there anymore (the field is empty).
Now, I went on and switched to the Visual Editor - Code view, and... it's not there. Nothing. I'm wondering: why is it showing when I'm in Classic View, but not on code view... clearly, if it's not there, it ain't saving!
After that, I added the code myself and what do I see: it's there, and saving, and still there.
To add the code myself is a big No-No because I'm building a site for a client... There must be a solution or a known patch...
(NB: I do not have any code to display since it's kindof in the backend... and not really code-ish related)
Can be reason 1: ACF fields not saving
I also had problem where the custom fields were not getting saved in the backend editor.
You should do a backup of the website before you try this. If you don't know how to do (save wp-content folder, export database), I recommend a free plugin called "All-in-One Migration" to do the backup.
My solution for ACF fields not getting saved:
Duplicate the field group in the ACF page. To do so go to the field group page of the acf plugin, hover the field group name, there should now be a link called "Duplicate".
After duplicating you delete the "old" field group. You can now name the new field group the way it was called.
You will notice that all the field names are still the same, so it will work if you got the fields echoed in the template files of the website. Do only now have new "keys" for the fields in the database.
Try to save the fields in the backend editor now, the problem with not saving fields should be solved.
This helped me when I deployed a website to another server. Sometimes the keys must be re-defined by using this duplicate method.
Can be reason 2: saving process can not complete
Edit the php.ini file on your webserver or contact the host to do so and increase max_input_vars and max_execution_time.
Maybe there are too many fields and values so there are more than the maximum allowed input vars. Or the saving process is taking too long because of lots of fields, so the maximum execution time is reached, saving process cannot run to the end of all fields.
I had this problem and solved it by erasing the files in the /theme-name/acf-json/fr/ directory. It happens to me once in a while. Probably because we are using WPML (that explains the /fr/) and the firm who made the website made all fields translatable.
I have inherited a multi-site in Drupal 7. There is a page where the client needs to edit the title element but this page is not a content type, a block or a taxonomy item!? I have queried the db and found only one instance of the value which needs to be changed. It is stored in the Variable table. If I change the value here the value changes as expected on the site. Can anyone shed any light on where the administration page is likely to be for this value based on the location of the value? I guess this could be defined anywhere really but was hoping someone may have come across this before.
You can change any variable value by using variable_set.
// Example
variable_set('variable_name', 'value to save');
Another way is to use devel module. After enabling the module; Go to ?q=devel/variable, find the variable you need to change from the table and click on Edit next to it.
The values of variables in Drupal can be set in a couple of ways:
From code - Using variable_set() function.
Look in the code if anywhere this function is called to set the value of the variable. If this is the case, you can implement your own module with some configuration form to override the value of the variable.
From a form defined using the Form API - Using system_settings_form() function.
I'll suggest you to look for the name of the variable who's value is used to set the page title, and then search in the code if there is a form element by that name, which is returned using system_settings_form. Then find out where this form is rendered - might be at some menu. After which you can change the value of this variable from the form itself.
I'm using Drupal 7.26 and i created a new content type.
I want to add a field that has a Default value where I can add PHP code. Normally, the Default value shows only plain text.
I have been activating "php filter module" and "cck module" for drupal 7.
But I cannot find the PHP code!!
How do I find this Item? Thank you.
You're looking at it differently.
PHP filter module will provide a text filter in which you would be able to enter php code.
However, the field type in which you add the php code needs to be "Large text" or "Large text with summary". In the field settings you have to enable the PHP filter, then you should be able to enter PHP.
Need help of Drupal experts.
My purpose (with Drupal 7 and Ubercart 3 in hands) is to add a custom field to the Checkout page, that should be dynamic (values from ajax request) and it content depends on user's delivery city input.
With "Extra Fields Pane" module I've successfully created field with some placeholder value. Than, I use JS methods to append values to that field. The problem has appeared when I submit form with that dynamic-added selected value - I have an "invalid selection" error for that field. When non-added-by-js value (placeholder) selected - everything works as expected.
Can you please hint me solution to that problem?
I found one here https://stackoverflow.com/a/5159013/837255 and it seems to be a common approach, but here other issue begins.
In %my module% in a hook I can't access field to do manipulations on it.
Example of how I need to make changes in created by module 'ajax_field_name':
$form['panes']['delivery']['ajax_field_name']['#ajax'] = ....
But my *cking pane has no any $form['panes']['delivery']['ajax_field_name']. When I do var_dump($form['panes']['delivery']) I see that 'ajax_field_name' located somewhere in $form['panes']['delivery']['address']['#uc_addresses_address'] OBJECT behind a private property.
function uc_nova_poshta_form_alter(&$form, &$form_state, $form_id){
if ($form_id == 'uc_cart_checkout_form'){
$obj = $form['panes']['delivery']['address']['#uc_addresses_address'];
// addressBook is a private property
$obj->addressBook;
}
}
In fact, this code does what I need -
$form['panes']['delivery']['address']['ajax_field_name2'] = array(
'#type' => 'select',
...
}
creates a custom field, in a right place, with access to it, BUT only in that form and this field does not affect any further activity (order review, admin pages, etc.). Also in $form['panes']['delivery'] this field ('ajax_field_name2') is located separately from created with module 'ajax_field_name'.
I guess the reason of this behavior are some modules e.g. uc_addresses (am I right?), but even when I disabled most suspicious of them - the problem is still there.
Is there a possibility to find out how to get access to 'ajax_field_name' created field?
Thank you.
This may not completely solve your problem (if you still have it as this seems a rather old question...), but one problem is you are using the wrong hooks. You should use hook_uc_checkout_pane_alter and target uc_checkout_pane_delivery to accomplish this. I learned this the hard way trying to set the default country selected to something other than US; things will break badly if you manipulate them via hook_form_alter and it's variants.
I'm working through something similar right now. I will update this answer with further information as I uncover it.
I have a few Views on my Drupal 6 site which take care of some of a node's fields.
For example, I have a content type called Country, which has a field called Capital. I've excluded this field in the node display, but there is a view that takes the node ID as an argument and displays it in the right column. This is all very pretty and has been working out well for me, but how do I take care of the node preview mode? Since the node isn't saved yet, the Capital field won't have its new value yet.
Note: I am ready to do some very dirty hacks to make this work :)
don't hack drupal! :)
One of not so simple and unchecked idea:
use hook_form_alter or hook_nodeapi with validate in custom module, there's you should see data of new capital field, save it somewhere (for example, into sessions), and show it's into block via theming Views field.