I have a Matrix field that I am using for an address.

I have 5 columns in total

Address 1 - Text Address 2 - Text City - Text County - P&T Dropdown Postal Code - Text

I have City and County marked as required.

Now using the standard short field name in Safecracker will not output the fields how I want them formatted, so I am breaking them out.

For example,

I have the following when it comes to address one...

<input type="hidden" name="address[row_order][]" value="row_new_0" />
<input type="text" class="span8" name="address[row_new_0][col_id_4]" />
<span class="help-block">Address (first line)</span>

This works fine for all the text fields, but I am not sure about how the best way to display the P&T dropdown field.

I am using a P&T dropdown, as it allows me to utilise option groups, which I am using like so

 -county 1
 -county 2
 - and so on...

Now the only way I have found to output this in safecracker, is to write out every option.

<select class="span6" name="address[row_new_0][col_id_6]">

<option value="" selected="selected">Select your county</option>
<optgroup label="England">
<option value="Avon">Avon</option>
<option value="Bedfordshire">Bedfordshire</option>



The problem with this is that it does not seem to validate. If I leave the select unchanged, it doesn't throw up the "required" error.

Another issue is that if I do complete the required fields, but make other errors on the form, when submitted, it does not remember the values I entered. Presumably this is due to it not have a value="something" - but I am not sure what 'something' should be.

Any help appreciated!

1 Answer 1


Rather than write out every option have you tried a tag pair for the the name of your field?

<select name="my_field_name" id="my_field_name">
            <option value="{option_value}"{selected}>{option_name}</option>

Off the top of my head I'm not sure how this would handle your groups though, I'm sure it's possible but give that a try and see if it yields any results first. That should go some way to solving the error too.

As for the values because you're posting the page it will reset all field values so you can just retain the values by setting it in the value attribute like so:



<input type="text" class="span8" name="address[row_new_0][col_id_4]" value="{field_name}" />

Where {field_name} is the name of your field.

  • Thanks for the response (sorry its taken a while for me to get back. The problem is the the P&T Dropdown field is actually a field within matrix field, so I don't think its possible to just use a short field name. Also, when I add value="{field_name}" I get an error, and the field is just filled out with ARRAY.?
    – shorn
    Commented Apr 4, 2013 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.