Validating a cloned/repeatable input (jQuery)

I’m trying to create a repeatable field an upload image input with image preview for my Theme Options page and I have the following:

function theme_options_validate( $_POST ){

if (isset($_POST['submit']) ) {
$theme_options = array();
    foreach ($_POST['image'] as $key => $value) {
        if (empty($value))  continue; 
        $theme_options[] = array(
            'image'     => $_POST['image'][$key],
        );
    }
$valid_input['image'] = $_POST['image'][$key];
}

return $valid_input;

}

for this input:

Read More
<input type="hidden" class="image" name="custom_options[image][]" value="<?php echo esc_url( $theme_options['image'] ); ?>" />

So far, everything works fine, the problem is that I’m using jQuery .clone() to clone this input and add more images, but the clone always overwrite the original input when submitting!

Tried using jQuery to count the input as well(name="custom_options[image][0],[1],[2]…”), but have had no luck, the clone never returns.

Any idea on how can I fix this?

Related posts

Leave a Reply