Fill input with array

In my jquery code I have:

$("#show").append("<img src=" +attachment.url+" alt="+attachment.alt+" title="+attachment.title+" description="+attachment.caption+" class='img-responsive img-thumbnail'/><input type='hidden' name='my_image_URL[]' value="+attachment.url+"></span>");

My jquery code adds fields for news selected images and fills inputs names my_image_URL

But this part of code PHP does not fill the input:

if ( isset( $_POST['my_image_URL'] ) ) {

        $urls = $_POST['my_image_URL'];
             echo '<input name="imagens_home" value="'.$json_encode($urls).'" />';

        }

Complete code:

options.php

 register_setting(
            'tema-setting-group',//string $option_group
            'imagens_home' //string $option_name
            //calback $sanitize_calback      
        );

---
    add_settings_field(
         'home-imagens-top',//string $id
         'Imagens',//String $title
         'tema_home_imgs',//string $calback
         'opcoes_do_tema',//string $page    
         'tema-home-options'//string $section
         //string $args          
         );

//calback
function tema_home_imgs(){   
        $urlsImagens = esc_attr( get_option( 'imagens_home' ) ); // RETURN DB DATA

        include( get_template_directory() . '/inc/templates/selecao_imagens.php');

        if ( isset( $_POST['my_image_URL'] ) ) {

        $urls = $_POST['my_image_URL'];
             echo '<input name="imagens_home" value="'.$json_encode($urls).'" style="width:300px"/>';

        }   
    }

selecao_imagens.php

<input id="my_upl_button" type="button" value="Escolher Imagens" /><br/>

    <div class="row">
            <div id="exibe" class="sortable">       

            <?php           
            $urls = json_decode($urlsImagens, true);
                if ($urls != '' ) {
                foreach ($urls as $url) { 
             ?>          
                    <img src="<?php echo $url;?>"  class="img-responsive img-thumbnail " />
                    <input name="my_image_URL[]" value="<?php echo $url;?>"/>

            <?php
                 };
                }
            ?>
    </div>
    </div>

theme_options.php

<?php settings_errors();?>

<form method=”post” action=”options.php”>
<?php settings_fields (‘tema-setting-group’); ?>

<?php do_settings_sections (
‘opcoes_do_tema’//string $page

); ?>

<?php submit_button ();

?>

</form>

Apparently, this is all ok, but I do not know where the error is.

After the submit the field becomes empty, print_r and var_drump return empty

Thanks

I tried:

echo '<input name="imagens_home" value="' . htmlspecialchars(json_encode($urls)) . '" />';

but it is not yet filling in the input.

I also tried only:

If (isset ($ _POST ['my_image_URL'])) {
 Print_r ($ _ POST ['my_image_URL']);

}

And nothing appears on the screen after submitting, in the form everything is saving correctly minus the input that I want to save the array. The action on the form looks like this:

<Form method = “post” action = “options.php”>

I’m using the Settings API

when I created a metabox for posts and pages with the following code in action, Isset works :

add_action( 'save_post', function ( $post_id ) {
	if ( isset( $_POST['my_image_URL'] ) ) { 
	    delete_post_meta( $post_id, 'my-image-for-post' ); 
		$urls = $_POST['my_image_URL'];		
		add_post_meta( $post_id, 'my-image-for-post', $urls );	
	}
});

For the home page, in options of my theme I´m using settings API:

//calback
function tema_home_imgs(){   
        $urlsImagens = esc_attr( get_option( 'imagens_home' ) ); // RETURN DB DATA

        include( get_template_directory() . '/inc/templates/selecao_imagens.php');

        if ( isset( $_POST['my_image_URL'] ) ) {

        $urls = $_POST['my_image_URL'];
             echo '<input name="imagens_home" value="' . htmlspecialchars(json_encode($urls)) . '" />';
        }   
    }

print_r ($urls); or var_dump($urls); Returns empty

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.