mercredi 19 septembre 2018

PHP if validation

I have the following validation:

if (count(json_decode($PostData['images'], true))) {
    $post_images = array_combine(range(1, count(json_decode($PostData['images']))), array_values(json_decode($PostData['images'])));
    $post_images = json_encode($post_images);
} else {
    $post_images = '{}';
    $jSON['trigger'] = AjaxErro("<b class='icon-checkmark'>Tem de inserir pelo menos uma imagem.", E_USER_WARNING);
    echo json_encode($jSON);
    die();
}

It validates a drag and drop image made in a HTML div. The problem is: If i drag an image it stores the image. But then the drag and drop stays empty and if i drag another image without refreshing the page, because $PostData['images'] is empty it throws a error that count(): Parameter must be an array or an object that implements Countable.

I tried to make the proper if validation so that it stores image in database using the if clause at second drag of image but without success...

Any ideas?

Aucun commentaire:

Enregistrer un commentaire