Saving custom hook

My Account Forums Plugin Support WP User Frontend Pro Saving custom hook

Viewing 15 posts - 1 through 15 (of 54 total)
  • Author
    Posts
  • #67652
    MareVisie
    Member

    Hi,

    I have created a piece of code that uses jquery-ui-autocomplete to populate an autosuggestion box. Everything seems to be working now, except for saving the values. If I choose a value and click update, the page refreshes and the value is gone.

    The code:

    
    <?php
    wp_enqueue_style('education-hook-style', plugins_url( '/style.css' , __FILE__ ));
    
    function add_scripts(){
    	wp_enqueue_script( 'jquery-ui-autocomplete' );?>
    	<script src="//code.jquery.com/jquery-1.10.2.js"></script>
    	<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script><?php
    }
    add_action('wp_enqueue_scripts', 'add_scripts');
    
    function render_education_hook() {
    	global $wpdb;
    	$institutions = $wpdb->get_results( 
    		"
    		SELECT id, naam 
    		FROM wp_instellingen
    		"
    	);
    ?>
    	<div class="<?php echo esc_attr( 'wpuf-label' ); ?>">
    		<label for="edu_institute">Huidige instelling: </label>
    	</div>
    	<div class="<?php echo esc_attr( 'wpuf-fields' ); ?>">
    		<input class="<?php echo esc_attr( 'textfield wpuf_wpuf_testfield_22' ); ?>" id="<?php echo esc_attr( 'edu_institute' ); ?>" size="<?php echo esc_attr( '40' ); ?>"></input>
    	</div>
    	<script>
    		$( "#edu_institute" ).autocomplete({
    			source: [ <?php foreach ($institutions as $institution) {
    				echo '"' . $institution->naam . '", ';
    			}; ?> ]
    		});
    	</script>
    	<?php
    }
    add_shortcode( 'education-hook', 'render_education_hook' );
    add_action( 'education-hook', 'render_education_hook');
    
    function update_my_brand_new_hook() {
        if ( isset( $_POST['edu_institute'] ) ) {
            update_post_meta( 'edu_institute', $_POST['my_custom_field'] );
        }
    }
    add_action( 'wpuf_add_post_after_insert', 'update_my_brand_new_hook' );
    add_action( 'wpuf_edit_post_after_update', 'update_my_brand_new_hook' );
    
    /* <input class="<?php echo esc_attr( 'textfield wpuf_edu_institute_199') ?>" id="<?php echo esc_attr( 'edu_institute' ); ?>" type="<?php echo esc_attr( 'text' ); ?>" data-required="<?php echo esc_attr( 'yes' ); ?>" data-type="<?php echo esc_attr( 'text' ); ?>" name="<?php echo esc_attr( 'edu_institute' ); ?>" placeholder value size="<?php echo esc_attr( '40' ); ?>"> */
    	?>
    

    Any help is appreciated.

    #67762
    towhid
    Participant

    Hello MareVisie,

    You have forgotten to name attribute and its value.

    Just insert this attribute(“my_custom_field”) into the <input> tag.

    Thanks

    #67776
    MareVisie
    Member

    Sadly that doesn't work:

    <input class="<?php echo esc_attr( 'textfield wpuf_edu_institute_22' ); ?>" id="<?php echo esc_attr( 'edu_institute' ); ?>" size="<?php echo esc_attr( '40' ); ?>" attribute("edu_institute") ></input>

    #67777
    MareVisie
    Member

    Nor with

    <input class="<?php echo esc_attr( 'textfield wpuf_edu_institute_22' ); ?>" id="<?php echo esc_attr( 'edu_institute' ); ?>" size="<?php echo esc_attr( '40' ); ?>" attribute("my_custom_field") ></input>

    #67814
    towhid
    Participant

    Hello MareVisie,

    You did not understand my reply.

    Please insert the following code instead of the previous code:

    <input class="<?php echo esc_attr( 'textfield wpuf_edu_institute_22' ); ?>" name="my_custom_field" id="<?php echo esc_attr( 'edu_institute' ); ?>" size="<?php echo esc_attr( '40' ); ?>"></input>

    Thanks

    #67819
    MareVisie
    Member

    Sadly, that still doens't work.

    #67952
    towhid
    Participant

    Hello

    Please try with this code:

    <input class="<?php echo esc_attr( 'textfield wpuf_edu_institute_22' ); ?>" name="my_custom_field" id="<?php echo esc_attr( 'edu_institute' ); ?>" value="<?php echo esc_attr( '40' ); ?>"></input>

    Thanks

    #67993
    MareVisie
    Member

    That simply sets the initial value of the field to '40', it doesn't save anything.

    #67997
    towhid
    Participant

    Hello MareVisie,

    It must need a “value” attribute in the input field. Without the value attribute, input field does not insert and select any data.

    Please check this documentation:

    http://docs.wedevs.com/using-action-hook-field/

    This might help you to get an idea how to bind the action hook in the form.

    Thanks

    #68011
    MareVisie
    Member

    I get that, however I want users to input a value and store that instead. Now it just says 40.

    #68025
    towhid
    Participant

    Hello MareVisie,

    Please refurbish your code as like as the documentation described.

    Just check the Step Number2 from the documentation.

    To get value from user just use the following code:

    $value = '';
      
        if ( $post_id ) {
            $value = get_post_meta( $post_id, 'your_meta_key', true );
        }

    Thanks

    #69029
    MareVisie
    Member

    I have tried re-doing the code following the guide again, sadly to no avail.

    Furthermore, I have copied the entire code from the documentation and put it in a separate file. The label and field are generated correctly, but I can't save the value I enter.

    #69160
    towhid
    Participant

    Please provide your login details(FTP) by using this form: http://wedevs.com/provide-login-details/. I will have a look what is going wrong.

    Thank you 🙂

    #69182
    MareVisie
    Member

    For security reasons, our server doesn't have ftp clients. Is there another way?

    #69265
    towhid
    Participant

    Hello MareVisie,

    If you send me the full site and its database then I can check it.

    Thanks

Viewing 15 posts - 1 through 15 (of 54 total)
  • The topic ‘Saving custom hook’ is closed to new replies.