I want to set the location address of a location cck field by submitting a custom form (custom module) and save it with node_save(), but somehow its not working for location. After saving the node the location is still empty (for other cck fields it works great).
This is a part of my code:
// ...
$values = $form_state['values'];
$node->field_address[0]['street'] = $values['street'];
$node->field_address[0]['postal_code'] = $values['postal_code'];
$node->field_address[0]['city'] = $values['city'];
// ...
$node_save($node);
What do I need to do, to correctly set the location address?
Comments
Comment #1
osopolarIt's also working for new nodes. But if I want to update an existing node with the provided address it wont work.
Comment #2
chrismiller627 commenteddid you ever figure this out?
Comment #3
osopolarNo, I'm still waiting for an explication.
Comment #4
yesct commentedI dont know if this helps... but I needed to copy the location info to another cck location field on the same node when/after it was being saved, I did it with two rules, the first to create the location
... need to attach the file
Comment #5
yesct commentedhere it is, sorry about the format with pre tags.
Comment #6
yesct commentedComment #7
osopolarIt doesn't seem to be the correct way to involve rules to accomplish that a changed location address will be saved by node_save.
Comment #8
yesct commentedsetting this to active, since there is no patch suggested yet.
To clarify, you are asking not for how to do it now, but for the module to be improved so that it will work the way you propose in the initial issue description? Maybe restating what you are looking for in more detail will help.
This might help, I think I remember I had to do something special as I was programatically setting the location cck values *the first time*, so I had to kind of create the location first, then I could change the values. So editing the values and setting for the first time might be two different cases to consider.
Comment #9
yesct commentedtagging.
and might be related to #756316: Default value for CCK field disappears after saving the node
Comment #10
guillaumev commentedHi,
Any news on this ? Because I'm having the exact same problem...
Another problem that I have is that it seems that source does not save. I'm trying to set source to 4 in order to use JIT Geocoding, but it always gets saved as 0...
Comment #11
strae commentedI get this working reading this post: http://blog.ryantan.net/2010/12/creating-nodes-programmatically-in-drupa...
The only thing that the article is missing (but it should be obvious), is that location_save() return the location id ($lid) or false in case of failure (I took a read to location.module file to confirm that).
Hope it helps.
Comment #12
osopolarI had a quick look at http://api.lullabot.com/location_save and saw that you can pass the location ID to location_save(&$location, ...) by setting $location['lid'], so that an existing location gets updated.
Comment #13
gateway69 commentedone of the things im unclear about is how to populate the location instance table which takes the users UID, with location_save then node_save this doesnt set the UID, or did I miss a paramater i needed to pass with node_save? or location_save
Comment #14
kevinquillen commentedlocation_save and location cck fields seems busted. It is very difficult to get information saved from a form using the API.
I have tried two ways of saving locations to a Content Profile node with a CCK Location field, based on readings:
In a custom form alter and custom module:
another way:
yet another way:
Each time, I get one of these results:
1. Location is saved, all the data matches in content_type_profile (LID), location, and location instance. No problem.
2. User goes to save on a custom frontend form, submits, address appears to be updated. Internal form (edit profile as user 1) is completely blank, but should be populated.
3. Admin edits customer location (profile node form), and when customer goes to their account, their address is blank.
It seems like there is some condition causing the Location CCK field value in the content type profile table to either be ahead by 1, or under by 1. For example if the location lid in the location table is 15000, I somehow wind up with 15001 or 14999 in the CCK field of the profile table.
I am confused as to why this is happening, because it seems like I am using the location_save correctly, and a handful of blog posts indicate this is the way to programatically save locations.
Comment #15
kevinquillen commentedThe ID in the content profile table is ALWAYS higher than whats in the location table, yet somehow still able to pull a location out for the forms. Then you edit, and nothing changes. I am utterly baffled at this.
Comment #16
kevinquillen commentedAlso, location_save($values, FALSE, array('nid' => $nid)); still creates a new lid even though the documentation says it will reuse the lid.
Comment #17
ilrecidivo commentedThanks!
+ 1
Comment #18
kiki Zeuh Monkey commented#14 It's work! Thanks!
Comment #19
legolasboClosing old D6 issues as D6 is end of life