I am trying to: Create a frontend form in CRED.
I have a custom Post called Commission Payments Received.
The logged in user will be an Admin and he will be adding a commission payment received on behalf of another registered user.
I want to be able to select the correct author/registered user to assign the post to.
So how do I display a select box showing the authors of a certain role to then assign the post to?
I have the following code in the three different places.
The select Box functions correctly and the HTML listed below.
Unfortunately the Author is always set to the admin who is logged in and not the selected author from the select box.
HTML
<select name="my_author_select" data-wpt-type="select" class="wpt-form-select form-select select" id="cred_form_1254_1-select-1-1444877006">
<option data-wpt-name="my_author_select" data-wpt-id="cred_form_1254_1_cred_form_1254_1-select-1-1444877006" data-wpt-type="option" class="wpt-form-option form-option option" value="27">James Taylor</option>
<option data-wpt-name="my_author_select" data-wpt-id="cred_form_1254_1_cred_form_1254_1-select-1-1444877006" data-wpt-type="option" class="wpt-form-option form-option option" value="34">Pieter Double</option>
<option data-wpt-name="my_author_select" data-wpt-id="cred_form_1254_1_cred_form_1254_1-select-1-1444877006" data-wpt-type="option" class="wpt-form-option form-option option" value="33">Jonathan Bidmead</option>
<option data-wpt-name="my_author_select" data-wpt-id="cred_form_1254_1_cred_form_1254_1-select-1-1444877006" data-wpt-type="option" class="wpt-form-option form-option option" value="12">Pieter Double</option>
</select>
View
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-item index=1]
{"value":"[wpv-user field="ID"]","label":"[wpv-user field="user_firstname"] [wpv-user field="user_lastname"]"}
[wpv-item index=other],
{"value":"[wpv-user field="ID"]","label":"[wpv-user field="user_firstname"] [wpv-user field="user_lastname"]"}
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
Cred Form
[credform class='cred-form cred-keep-original']
[cred_field field='form_messages' value='']
[cred_generic_field field="my_author_select" type="select" class="" urlparam=""]
{
"required":0,
"validate_format":0,
"persist":1,
"default":[],
"options":[ [wpv-view name="List Authors"] ]
}
[/cred_generic_field]
<div class="cred-group cred-group-Commission-Payments-Received">
<div class="cred-header"><h3>Commission Payments Received</h3></div>
<div class="cred-field cred-field-commission-amount">
<label class="cred-label">
Commission Amount
</label>
[cred_field field='commission-amount' post='comm-acc-payment' value='' urlparam='']
</div>
<div class="cred-field cred-field-policy-commission-received-from">
<label class="cred-label">
Policy Commission Received From
</label>
[cred_field field='policy-commission-received-from' post='comm-acc-payment' value='' urlparam='']
</div>
</div>
[cred_field field='form_submit' value='Submit' urlparam='']
[/credform]
Functions File
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==1254)
{
$my_post = array(
'ID' => $post_id,
'post_author' => $form_data['my_author_select']
);
// Update the post into the database
wp_update_post( $my_post );
}
}
I fixed it in the end
I had to change
'post_author' => $form_data['my_author_select']
as it was trying to insert the 'label' rather than the 'id' into the post.
to
'post_author' => $_POST['my_author_select']