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.
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 a situation where I need to create a shortcut for a specific filter in a Joomla component.
The problem is that I cannot unset it, as I do not know if Joomla sets the form fields to its own session handler, request handler or some kind of custom handler. There also does not appear to be any documentation on this specific case.
The full situation is that I have a link that will auto filter in the same view as another link (in the components sidebar). One view will be just a specific filter and the other is standard. So I need it when you click into the filtered view it will reset the current filters to make sure everything displays as it should, and vice-versa so clicking back will again reset the filters.
I have tried a number of approaches for this, and although I can consistently force it to filter but it will not reset the form when I re-enter the last page with any technique I have tried so far and of course I want to avoid bypassing Joomla's default functions.
if(JRequest::getVar('filter_group_id',false)==10){
JRequest::setVar('last_filter',true);
EthicstoolHelper::addSubmenu('supervisors');
}else{
if(JRequest::getVar('last_filter',false)===true){
JRequest::setVar('last_filter',false);
JRequest::setVar('filter_group_id',false)
}
EthicstoolHelper::addSubmenu('users');
}
This is the most recent think I have tried, as you can see I try to reset the value to false in a hope that Joomla will read it as not being set, as JRequest has no built in unset method.
I don't have enough rep to comment yet, so I'm guessing a bit as to what the problem could be. Assuming that you are using a model to set the state of the filters, you can look at overriding the populateState method.
Another options is to fiddle with the context property in the model. For example, you could change the context if you have your special filters enabled if you are using things like $app->getUserStateFromRequest(). If you can post a bit more information about the design of your component (controllers and models), I can help more.
How can I add a form or HTML output to plgVmOnSelectPayment()?
I see no documentation about that.
I don't know this event Virtuemart payment select works.
I want add after selection a form with input fields.
Can anyone help ?
The plgVmOnSelectPayment() from what I've reversed engineered doesn't give any output to the HTML, but you can modify the cart content with that event.
I was myself in need of adding a form after a particular payment method was selected (to guarantee some additional data being supplied). Depending on where you want it you can either edit the View for the cart and add an if-statement where you see if the particular payment method is chosen. And then later access this information from plgVmConfirmedOrder() (you can access it through the $_POST global.
(This is an untested theory)
If you want to add the information to the field you can access the display form and add information there through the plgVmDisplayListFEPayment() event. Look in the vmPSPlugin class to see how they manage it there. What I did was simply copy that to get an image into that form, but you should be able to add other things there as well. And then you might be able to access the information there through plgVmOnSelectPayment() and using the $_POST global.
As a fair warning. All this I've gotten through reverse engineering VirtueMart. So it's neither pictue perfect nor might it be best practice. But the VirtueMart documentation leave not many other options :(. So if someone have a better way, I'm very interested in knowing that as well!
I am working on a pair of form fields the directly effect one another. Specifically the problem I am dealing with is that we have thousands of groups users can join on this website that I have been working on. We are creating some administrative analytics forms for the site. Part of those forms is filtering by group.
The problem is that most of the people don't know the name of a group off the top of their heads, only what it starts with. So instead of using auto-complete we came up with two dropdowns. The first contains the options A through Z, letters of the alphabet which the group names begin with. The second dropdown contains all of the groups beginning with the selected letter.
The concept is simple enough and we were able to implement the AJAX pretty easy with jQuery. But this causes validation errors. After some research I found that this has to do with Drupal form caching. The solution is to use the ahah functions.
The problem with that is that all the instructions I have found so far deal with ahah actions for the specified field updating itself, not another field. So I am trying to figure out how to get the list of letters to update the group list using ahah and registering the new values with the form cache.
One solution I found was to simply load all the values on the page in a hidden dropdown and then just load up those in the set in the visible one as needed. But that creates a bunch of problems because the client uses almost exclusively IE and we have seen IE choke when given huge lists like that. Especially with the lists stored in JavaScript. So we need a light-weight solution.
Any thoughts? Ideas?
In a nutshell AHAH works like this:
Form gets generated with an empty $form_state
When an element that has the #ahah property gets changed an ajax call is made to the url specified as path in the #ahah property.
The callback at that url does this:
Retrieves the form from the form cache
Processes the form
Rebuilds the form with a current $form_state so that it can add / change elements based on that
The form is put in the form cache to avoid validation errors
The form is rendered and returned as JSON
Drupal replaces the contents of the wrapper div with the new form.
In your case you'll need to make your form generation function aware of the values selected in $form_state. It would have to:
Generate the letters drop-down
Look into $form_state and see if there is a letter selected. If so, generate the second drop-down based on the selected value.
The callback function would implement the form caching and rebuilding.
There are good explanations with code for the callback function here:
http://drupal.org/node/348475
http://drupal.org/node/331941
I actually got the answer on another StackExchange site. His suggestion to use the example module to come up with the solution worked very well.
Solution found here: https://drupal.stackexchange.com/questions/35048/using-drupal-6s-form-ahah-to-have-one-dropdown-field-update-the-values-of-a-sec
I would like to add a validation function to every form field on the Drupal registation page, including the custom Profile fields I've added.
Is there a simple way to do this without manually attaching it to each field? Would like it to support future profile fields that may be added without having to manually update the code.
Depending on the complexity of the validation, the Validation API module may be able to do what you need. Be aware that the module is no longer being actively maintained though.
Depending on your needs, the Clientside Validation module might also work, though the rules wouldn't be applied to users with Javascript disabled.
I'm assuming you're on D6.
You can kinda see what you need to validate here:
http://api.drupal.org/api/drupal/modules--profile--profile.module/function/profile_form_profile/6
If you implemented something with hook_elements you could validate anything the profile module creates. It shouldn't be too hard if you've got some good developer skills.
http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_elements/6
You can access the form with a hook_form_alter, and add one of more additional form validators.
Make sure you don't overwrite your default validator, but just add an extra one.
$form['#validate'][] = 'my_custom_validate';
This extra validate handler could loop over the profile fields and check for empty entries for example, or something else.