Home Forums Plugin Support WP User Frontend Pro Can't save custom fields with custom dropdown in a hook

This topic is: resolved

This topic contains 2 replies, has 2 voices, and was last updated by  Olivier 4 years, 3 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #39193

    Olivier
    Member
    Post count: 31

    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' );
    #39247

    towhid
    Participant
    Post count: 4505

    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 ๐Ÿ™‚

    #39250

    Olivier
    Member
    Post count: 31
    This reply has been marked as private.
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Can't save custom fields with custom dropdown in a hook’ is closed to new replies.