Page 1 of 1

No Image Uploaded - default image req'd

Posted: 2023-10-12 22:25
by ronwill
HI, I would like some help regarding the following, I don't know if the solution is via hooks or using js!

Required: I would like to automatically have a default image load onto my DV template (+tv but not imperative) when a member does not upload a profile picture. The image field is not mandatory its member choice, however rather that having no image or a default small gif when they don't upload an image I'd like to show a standard default image.
It needs to apply to just one group (member) for my senario and the default image would apply to all/any user that decides not to upload/save an image to their record.

I'm sure there must be a simple way to achieve this (I even think I did it before years ago!) but my memory is not what it once was, so I've forgotten how - pls help, thank you.

Re: No Image Uploaded - default image req'd

Posted: 2023-10-13 20:55
by pbottcher
Hi
you could add an image to the images folder and use sql to add this image in the after insert hook.

Re: No Image Uploaded - default image req'd

Posted: 2023-10-14 13:45
by ronwill
Hi,

Not having much luck - lattest effort was

Code: Select all

	function your_horse_after_update(&$data, $memberInfo, &$args) {

    if($data['horse_pic'] == "null") {
		$j('#horse_pic-image').attr('src', './images/no_image.png');        
		
        return false;
    }		
		return TRUE;
	}
my table = your_horse
my field = horse_pic
my image to be shown if the user does not upload an image when creating or updating their file/record is = no_image.png (in images folder)

Hope you can guide me, thanks

Re: No Image Uploaded - default image req'd

Posted: 2023-10-14 15:12
by jsetzer
$data['horse_pic'] == "null"
Are you sure this is a string ?

Try null instead of "null"

If you want to be sure, dump out the current value:

Code: Select all

var_dump($data);
exit;
Don't forget to remove those two lines later on.

Re: No Image Uploaded - default image req'd

Posted: 2023-10-14 15:13
by pbottcher
Hi Ron,

try in the function your_horse_after_insert and function your_horse_after_update

Code: Select all

if (empty($data['horse_pic'])) {
	$eo=[];
	$sql="UPDATE your_horse set horse_pic='no_image.png' where id={$data['selectedID']}";
	sql($sql,$eo);
}

Re: No Image Uploaded - default image req'd

Posted: 2023-10-14 16:08
by ronwill
Hi pböttcher,
Placed code as you advised in your_horse_after_insert and function your_horse_after_update.
It worked perfectly - thank you so much, I'd never have found that solution myself.
Cheers,
Ron