Greetings!
I need to set the default value of a location form item via a link from another node.
Example:
A coordinate is saved in node/16. When viewing node, by clicking link 'add note to this location', the content type
'note' input form is loaded, containing coordinates inherited from node/16.
Any clue how I can do this? :)
Thanks
Comments
Comment #1
farald commentedThis is easily applied to other fields by modifying the default values of the node/add/nodetype $form.
But where in the $form array are the default values for the locations?
I have tried multiple solutions, but none seems to work. Some even changes the
default value ->in the array,but still, the node form are not showing the inserted new values from the array.
Now Im stuck.
Comment #2
farald commentedComment #3
yesct commentedis this where form_alter could be used?
There are some other posts in the location issue queue about form_alter
Maybe they could help you?
http://drupal.org/project/issues/search/location?text=form_alter&assigne...
Comment #4
yesct commented#423662: How to set default latlon by editing the form values? was marked as a duplicate of this issue.
Comment #5
farald commentedIve found a a solution to this (a hack, but still). For reference:
#143289: Pre-populate node location from author/organic group etc. comment no #7.
This hack enables locations to be set at user's location.
I need to be able to create nodes with lat/lon inherited from previous node.
If no node to inherit from, the location needs to be set at the user's location (users only post nodes to their immediate area)
The easiest way is to check for a node id in arg(3) after node/add/nodetype/ to inherit from.
So i replaced ron_s's first part with this:
Then I used the last part as it was.
Comment #6
yesct commentedchanging this to code needs work. Maybe someone can take what you started and use it to write a patch for location to get this in officially? :) If this sits here for a while with no-one running with what you started, I might mark it postponed.
and tagging with useful code.
Comment #7
yesct commentedComment #8
rooby commentedLocation form elements cannot be modified using hook_form_alter().
Instead use hook_locationapi() that the location module provides.
For an example of setting default values see #367218: How to force a default on Location Name and disable/protect form input