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_randvar_drumpreturn emptyThanks
The topic ‘Fill input with array’ is closed to new replies.