Can't save custom fields with custom dropdown in a hook

This topic contains 2 reply and 2 voices, and was last updated by Olivier 9 years, 1 month ago
Viewing 2 Posts - 1 through 2 (of 2 total)
Author Posts
March 15, 2015 at 10:09 pm 39193
Olivier Hi there, I created a custom dropdown menu made of custom post types title. I followed the steps you give to create your own hook (http://docs.wedevs.com/using-action-hook-field/) but when I save, it doesn't save into the custom field. Please help, here is my code :
/* Adds a dropdown menu with all the adresses for Devis
*
* @param int $form_id
* @param null|int $post_id
* @param array $form_settings
*
*/
function list_adresses( $form_id, $post_id, $form_settings ) {
    
    $current_user = wp_get_current_user();
        
    $args = array(
        'post_type'  => 'adresses',
        'numberposts' => -1,
        'author'      => $current_user->ID
    );
    
    $the_query = new WP_Query( $args );
    
    $out = '<div class="wpuf-label">
            <label for="wpuf-post_title">Adresse <span class="required">*</span></label>
            </div>';
    $out .= '<div class="wpuf-fields"><select id="wpse34320_select"><option>Selectionner une adresse</option>';
    
    if( $the_query->have_posts() ):
        while ( $the_query->have_posts() ) : $the_query->the_post();
        
            $adresse_complete = get_the_title(). ' - '. get_field("adresse");
            $out .= '<option value="' . $adresse_complete . '" name="devis_adresse_new">' . $adresse_complete . '</option>';
            
        endwhile;
    endif;
    
    $out .= '</select> ';
    $out .= '<a style="position: relative; z-index: 1;" class="btn-bleu" href="/ajouter-une-adresse/">Ajouter une adresse</a>';
    $out .= '</div>';
    
    echo $out;
    
    wp_reset_query(); 
}
add_action('form_list_adresses', 'list_adresses', 10, 3 );

/**
 * Update the custom field when the form submits
 *
 * @param type $post_id
 */
function update_form_list_adresses( $post_id ) {
    if ( isset( $_POST['devis_adresse_new'] ) ) {
        update_post_meta( $post_id, 'devis_adresse', $_POST['devis_adresse_new'] );
    }
}
add_action( 'wpuf_add_post_after_insert', 'update_form_list_adresses' );
add_action( 'wpuf_edit_post_after_update', 'update_form_list_adresses' );
March 16, 2015 at 5:22 pm 39247
towhid towhid

Hello Olivier,

You have missing name="" attribute in “<select id=”wpse34320_select”><option>Selectionner une adresse</option>’;” . Put name=”” attribute in select field and see what happen and let me know the result.

Thank You 🙂

March 16, 2015 at 6:28 pm 39250
Olivier Olivier This reply has been marked as private.
Viewing 2 Posts - 1 through 2 (of 2 total)