I am using Drupal 7 and have figured out the text fields and a taxonomy dropdown but having no luck with an address field picking a state or country. my content type is directory-listing

the url below doesn't work -- but for a taxonomy dropdown the same logic works (using the "name" attribute and the value)

http://MY DOMAIN NAME.com/node/add/directory-listing?edit[field_address][und][0][administrative_area]=AK

-html...
select id="edit-field-address-und-0-administrative-area" class="state form-select" size="0" 
name="field_address[und][0][administrative_area]">
<option selected="selected" value="">--</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
more options....

for the radio buttons I have (content type testing)

http://my domain/node/add/testing?edit[field_my_radio][und]=1  (doesn't work)

<div class="form-item form-type-radios form-item-field-my-radio-und">
<label for="edit-field-my-radio-und">my radio </label>
<div id="edit-field-my-radio-und" class="form-radios">
<div class="form-item form-type-radio form-item-field-my-radio-und">
<input id="edit-field-my-radio-und-none" class="form-radio" type="radio" value="_none" name="field_my_radio[und]">
<label class="option" for="edit-field-my-radio-und-none">N/A </label>
</div>
<div class="form-item form-type-radio form-item-field-my-radio-und">
<input id="edit-field-my-radio-und-1" class="form-radio" type="radio" value="1" name="field_my_radio[und]">
<label class="option" for="edit-field-my-radio-und-1">One </label>
</div>
<div class="form-item form-type-radio form-item-field-my-radio-und">
<input id="edit-field-my-radio-und-2" class="form-radio" type="radio" value="2" name="field_my_radio[und]">
<label class="option" for="edit-field-my-radio-und-2">Two </label>
</div>
CommentFileSizeAuthor
#5 prepopulate-add-radios-1424774-5.patch371 bytesscuba_fly

Comments

cimo75’s picture

+1 for radio buttons

mototribe’s picture

I don't think prepopulate will work with address field because the way the "address" array is structured:

You can prefill it in a hook_form_alter() with something like:
$form['field_address'][LANGUAGE_NONE][0]['#address']['country'] = 'US';
$form['field_address'][LANGUAGE_NONE][0]['#address']['locality'] = 'Livermore';
$form['field_address'][LANGUAGE_NONE][0]['#address']['administrative_area'] = 'CA';
$form['field_address'][LANGUAGE_NONE][0]['#address']['postal_code'] = '94551';

mototribe’s picture

Issue summary: View changes

added

rbrownell’s picture

Any movement on this? Surely prepopulate can adapt the the array structure.

EDIT: I have given up on this module instead opting to use a combination of Rules and Rules Links to achieve the same functionality.

nodecode’s picture

@rbrownell is there any wisdom you can share about using rules to prepopulate address fields? I'm experimenting with a combination of these modules: rules + pathrules + rules_url_argument.

I'm able to get Rules to recognize a url argument and use it as a variable. But I'm stuck trying to get Rules to interact with my form. I'm using "Execute Custom PHP code" because I assume this is the only way to alter the form. Can you share any code or give us a basic rundown of your method?

Thank you in advance for your contribution

scuba_fly’s picture

Component: Documentation » Code
Category: Support request » Feature request
Status: Active » Needs review
StatusFileSize
new371 bytes

Having this issue, I created a patch for this.

Using this patch you can add the value like so:

edit[field_training_festival][und]=710

If the output of your field was like so

<div class="form-item form-type-radios form-item-field-training-festival-und">
 <div id="edit-field-training-festival-und" class="form-radios"><div class="form-item form-type-radio form-item-field-training-festival-und">
 <input id="edit-field-training-festival-und-709" name="field_training_festival[und]" value="709" class="form-radio" type="radio">
</div>
<div class="form-item form-type-radio form-item-field-training-festival-und">
 <input id="edit-field-training-festival-und-710" name="field_training_festival[und]" value="710" checked="checked" class="form-radio" type="radio">
</div>

Removed the labels to make the output a bit more clean.

dbazuin’s picture

I added Prepopulate to a site and tried to use it on a list field.

When I tried to use ?edit[field_lijstje][und]=c the field still had the default value.
After I applied "prepopulate-add-radios-1424774-5.patch" the value of the field changed to c.

So +1 for this patch.