This topic contains 53 reply and 3 voices, and was last updated by towhid 3 years, 11 months ago
Viewing 15 Posts - 1 through 15 (of 53 total)
Author Posts
August 17, 2015 at 6:19 pm 67652
towhid 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.
August 18, 2015 at 1:22 pm 67762
towhid towhid

Hello MareVisie,

You have forgotten to name attribute and its value.

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

Thanks

August 18, 2015 at 3:23 pm 67776
MareVisie MareVisie

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>

August 18, 2015 at 3:25 pm 67777
MareVisie MareVisie

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>

August 18, 2015 at 6:12 pm 67814
towhid towhid

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

August 18, 2015 at 6:21 pm 67819
MareVisie MareVisie

Sadly, that still doens’t work.

August 19, 2015 at 10:33 am 67952
towhid towhid

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

August 19, 2015 at 2:37 pm 67993
MareVisie MareVisie

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

August 19, 2015 at 3:12 pm 67997
towhid towhid

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

August 19, 2015 at 4:44 pm 68011
MareVisie MareVisie

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

August 19, 2015 at 5:41 pm 68025
towhid towhid

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

August 25, 2015 at 7:02 pm 69029
MareVisie MareVisie

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.

August 26, 2015 at 6:19 pm 69160
towhid towhid

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 🙂

August 26, 2015 at 6:52 pm 69182
MareVisie MareVisie

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

August 27, 2015 at 10:03 am 69265
towhid towhid

Hello MareVisie,

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

Thanks

August 27, 2015 at 1:10 pm 69297
MareVisie MareVisie

Towhid,

I have filled in the form for providing login details. I have put the login for PHPMyAdmin in the FTP section. Hope that’s enough.

Viewing 15 Posts - 1 through 15 (of 53 total)