Public Submission Form: Check if Image is Uploaded

Hi there.

I have several fileds being validated with a validation handler for our public submission form and they’re working great. One field I have validating is “event_image_alt” for the image alt text. However, I only want that validated if an image has been uploaded. Is it possible for the handler to check that an image has been uploaded on that form? I know this isn’t the syntax but I need something like this…

if (!empty($_LW->_POST[‘event_image_upload’])) {
if (empty($_LW->_POST[‘event_image_alt’])) {
$_LW->REGISTERED_MESSAGES[‘failure’]=‘The image alt text is required.’;
};
};

Thank you in advance!

Hi Adam,

Sure thing – “uploader_response_image” is the POST variable associated with an uploaded image, so I think what you want is something like

if (!empty($_LW->_POST['uploader_response_image'])) { // if uploading an image
    if (empty($_LW->_POST['event_image_alt'])) {
        $_LW->REGISTERED_MESSAGES['failure']='The image alt text is required.';
    };
};

in your onValidatePublicSubmission handler code, that should do the trick.

Hey Karl.

Indeed that did work!

Thanks so much.
Adam

1 Like