I have the following function with an array of variables that handles a profile form. All but one is a typical input with the exception of 'member-comptency[]'
. It’s a select field field with several possible values. Right now, the form saves, all the data comes through as expected with the exception of that field which simply returns a number which I assume is the html value
. In looking at it a bit more, the "value" of the element is simply a number also which might make matters worse.
I’ve tried in vain several times to modify this in different ways, but only produces a ‘no-save’ situation, or further non-descrip errors. I understand this field is an array itself, but not sure how to even ask a better question to get myself on track.
The function
function getUMFormData(){
$id = um_user('ID');
$names = array(
'member-company',
'member-phone',
'member-website',
'member-competency[]',
'member-contact-billing-name'
);
foreach( $names as $name )
update_user_meta( $id, $name, $_POST[$name] );
}
The HTML element
One of several choices
<label class="um-field-radio um-field-half right ">
<input type="radio" name="member-competency[]" value="1">
<span class="um-field-radio-state">
<i class="um-icon-android-radio-button-off"></i>
</span>
<span class="um-field-radio-option">Manufacturer</span>
</label>
The desired outcome
I need to get the the word from the last <span>
element (Manuracturer in the example) to save into the getUMFormData()
function.
2
Answers
I suppose ‘member-competency[]’ is not the right way to access an array of values within the post array. You could try to var_dump() or print_r() the $_POST[‘member-competency’]; See if the array is displayed properly.
From your HTML example, note that the "Manufacturer" radio button has "1" as value.
Now, in your function, the meta key to be used is
'member-competency'
without[]
.Then note that
$_POST['member-competency']
will give an array likearray('1')
because of[]
inmember-comptency[]
attribute name from the input radio button HTML.If you get
array('1')
from$_POST['member-competency']
is that the selected radio button is "Manufacturer", and you can set "Manufacturer" as meta value.So your function will be:
It should work.