No Image Uploaded - default image req'd

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
User avatar
ronwill
Veteran Member
Posts: 230
Joined: 2015-08-08 10:12
Location: Cheltenham UK +Weatherford USA

No Image Uploaded - default image req'd

Post by ronwill » 2023-10-12 22:25

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.
Ron - Gloucestershire, UK: AppGini Pro V 23.15 Rev 1484 - LOVING IT!
Plugins: Mass Update + Search Page Maker + Summary Reports + Calendar + Messages
Bizzworxx: AppGiniHelper + Inline Detail View
Alejandro Landini: To-Do List + MPI + TV Field Editor
Other: Udemy Course

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1709
Joined: 2018-04-01 10:12

Re: No Image Uploaded - default image req'd

Post by pbottcher » 2023-10-13 20:55

Hi
you could add an image to the images folder and use sql to add this image in the after insert hook.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
ronwill
Veteran Member
Posts: 230
Joined: 2015-08-08 10:12
Location: Cheltenham UK +Weatherford USA

Re: No Image Uploaded - default image req'd

Post by ronwill » 2023-10-14 13:45

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
Ron - Gloucestershire, UK: AppGini Pro V 23.15 Rev 1484 - LOVING IT!
Plugins: Mass Update + Search Page Maker + Summary Reports + Calendar + Messages
Bizzworxx: AppGiniHelper + Inline Detail View
Alejandro Landini: To-Do List + MPI + TV Field Editor
Other: Udemy Course

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1944
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: No Image Uploaded - default image req'd

Post by jsetzer » 2023-10-14 15:12

$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.
Last edited by jsetzer on 2023-10-14 15:14, edited 1 time in total.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 25.10 + all AppGini Helper tools

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1709
Joined: 2018-04-01 10:12

Re: No Image Uploaded - default image req'd

Post by pbottcher » 2023-10-14 15:13

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);
}
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
ronwill
Veteran Member
Posts: 230
Joined: 2015-08-08 10:12
Location: Cheltenham UK +Weatherford USA

Re: No Image Uploaded - default image req'd

Post by ronwill » 2023-10-14 16:08

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
Ron - Gloucestershire, UK: AppGini Pro V 23.15 Rev 1484 - LOVING IT!
Plugins: Mass Update + Search Page Maker + Summary Reports + Calendar + Messages
Bizzworxx: AppGiniHelper + Inline Detail View
Alejandro Landini: To-Do List + MPI + TV Field Editor
Other: Udemy Course

Post Reply