• Resolved mortenamdk

    (@mortenamdk)


    Hi have som problems with nonce my function i can not make it work.
    Maybe there are some there can see whats what i am doing wrong.

    function ajax_(hidden)_update_top_banner() {
        global $wpdb;
          $table_name = $wpdb->prefix . "topbanner";
    
          if ( isset( $_REQUEST['name_of_nonce_field'] ) && $_POST['name_of_nonce_field'], 'name_of_my_action' ) ) {
    
      $(hidden)_top_banner_name                  = wp_kses_post($_REQUEST['(hidden)_top_banner_name']);
      $(hidden)_top_banner_name_color            = sanitize_hex_color($_REQUEST['(hidden)_top_banner_name_color']);
      $(hidden)_top_banner_name_top_text_line    = sanitize_text_field($_REQUEST['(hidden)_top_banner_name_top_text_line']);
      $(hidden)_top_banner_name_top_height       = sanitize_text_field($_REQUEST['(hidden)_top_banner_name_top_height']);
      $(hidden)_top_banner_name_top_start_date   = sanitize_text_field($_REQUEST['(hidden)_top_banner_name_top_start_date']);
      $(hidden)_top_banner_name_top_stop_date    = sanitize_text_field($_REQUEST['(hidden)_top_banner_name_top_stop_date']);
      $(hidden)_top_banner_name_media            = sanitize_text_field($_REQUEST['(hidden)_top_banner_name_media']);
      $(hidden)_image_attachment_id              = sanitize_text_field($_REQUEST['(hidden)_image_attachment_id']);
      $id																					= $_REQUEST['id'];
    
    $wpdb->update(
    $table_name,
    array(
          '(hidden)_top_banner_name'                   => $(hidden)_top_banner_name,
          '(hidden)_top_banner_name_color'             => $(hidden)_top_banner_name_color,
          '(hidden)_top_banner_name_top_text_line'     => $(hidden)_top_banner_name_top_text_line,
          '(hidden)_top_banner_name_top_height'        => $(hidden)_top_banner_name_top_height,
          '(hidden)_top_banner_name_top_start_date'    => $(hidden)_top_banner_name_top_start_date,
          '(hidden)_top_banner_name_top_stop_date'     => $(hidden)_top_banner_name_top_stop_date,
          '(hidden)_top_banner_name_media'             => $(hidden)_top_banner_name_media,
          '(hidden)_image_attachment_id'               => $(hidden)_image_attachment_id,
    ),
    
    array( 'id' => $id ),
    array(
      '%s',
      '%s',
          '%s',
          '%s',
          '%s',
          '%s',
          '%s',
          '%d',
    ),
    array( '%d' )
    );
    } else {
      print 'Sorry, your nonce did not verify. It is a secure WordPress site. go get a coffee !!';
      exit;
      }
    
          // Always die in functions echoing ajax content
         die();
    }
    
      add_action( 'wp_ajax_ajax_(hidden)_update_top_banner', 'ajax_(hidden)_update_top_banner' );
    <form method="post" action="">
        <div class="plugin_(hidden)_banner">
            <div><label for="(hidden)_top_banner_name"><b>Banner tekst</b></label></div>
            <?php
    
                      $(hidden)_top_banner_name = $(hidden)_top_banner->(hidden)_top_banner_name;
            wp_editor( $(hidden)_top_banner_name, '(hidden)_top_banner_name'.$(hidden)_top_banner->id.'', array(
                'wpautop'       => true,
                'media_buttons' => true,
                'textarea_rows' => 1,
            ) );?>
    				<div class="edit_line_height_container">
    				<b>Height p? banner linjen</b> <input type="number" maxlength="4" size="4" name="(hidden)_top_banner_name_top_height<?php echo $(hidden)_top_banner->id; ?>" id="(hidden)_top_banner_name_top_height<?php echo $(hidden)_top_banner->id; ?>" value="28">
    				<b>Tekst linje h?jde</b> <input type="text" size="4" name="(hidden)_top_banner_name_top_text_line<?php echo $(hidden)_top_banner->id; ?>" id="(hidden)_top_banner_name_top_text_line<?php echo $(hidden)_top_banner->id; ?>" value="1.8">
    			</div>
        </div>
        <div class="plugin_(hidden)_top_banner">
          <div><label><b>Baggrundsfarve</b><br></label><input type="text" class="color-picker" data-alpha="true" name="(hidden)_top_banner_name_color<?php echo $(hidden)_top_banner->id; ?>" id="(hidden)_top_banner_name_color<?php echo $(hidden)_top_banner->id; ?>" value="<?php echo $(hidden)_top_banner->(hidden)_top_banner_name_color; ?>" />
            <button type="submit" name="submit_delete<?php echo $(hidden)_top_banner->id; ?>" id="submit_delete<?php echo $(hidden)_top_banner->id; ?>">Slet banner</button>
            </div>
    
            <label><b>Baggrundsbillede</b></label>
            <div class='image-preview-wrapper<?php echo $(hidden)_top_banner->id; ?>'>
    			<img id='image-preview<?php echo $(hidden)_top_banner->id; ?>' src='<?php echo $(hidden)_top_banner->(hidden)_top_banner_name_media; ?>' width='100%'>
    		</div>
        <label><b>Vis billede</b></label>
            <input type='checkbox' name="(hidden)_top_banner_name_media<?php echo $(hidden)_top_banner->id; ?>" id="(hidden)_top_banner_name_media<?php echo $(hidden)_top_banner->id; ?>" value="<?php echo $(hidden)_top_banner->(hidden)_top_banner_name_media; ?>" checked />
    		<input id="upload_image_button<?php echo $(hidden)_top_banner->id; ?>" type="button" class="button" value="<?php _e( 'Upload banner billede' ); ?>" />
    
            <div><b>Start</b></div>
            <input type="text" class="date_picker plugin_(hidden)_top_banner_dato" name="(hidden)_top_banner_name_top_start_date<?php echo $(hidden)_top_banner->id; ?>" id="(hidden)_top_banner_name_top_start_date<?php echo $(hidden)_top_banner->id; ?>" value="<?php echo $(hidden)_top_banner->(hidden)_top_banner_name_top_start_date; ?>">
    
            <div><b>Slut</b></div>
            <input type="text" class="date_picker plugin_(hidden)_top_banner_dato" name="(hidden)_top_banner_name_top_stop_date<?php echo $(hidden)_top_banner->id; ?>" id="(hidden)_top_banner_name_top_stop_date<?php echo $(hidden)_top_banner->id; ?>" value="<?php echo $(hidden)_top_banner->(hidden)_top_banner_name_top_stop_date; ?>"><br><br>
            <input type="hidden" name="id" id="id" value="<?php echo $(hidden)_top_banner->id; ?>">
    <?php wp_nonce_field( 'name_of_my_action', 'name_of_nonce_field' ); ?>
            
        <input type="submit" name="submit_update<?php echo $(hidden)_top_banner->id; ?>" id="submit_update<?php echo $(hidden)_top_banner->id; ?>" value="Gem ?ndringer" class="button-primary">
    	</div>
            </form>

    Best regards
    Morten

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Nonce in ajax request’ is closed to new replies.