*

TailerLan

  • **
  • 21 posts
It is obligatory to insert a photo in a new ad.
« on: September 11, 2022, 11:29:38 AM »
Is it possible to make the photo insertion field required when creating a new listing?

*

mwindey

  • *****
  • 485 posts
Re: It is obligatory to insert a photo in a new ad.
« Reply #1 on: September 11, 2022, 12:26:32 PM »
@ TailerLan

Also for that there is a plugin called image-required.
https://osclasspoint.com/osclass-plugins/design-and-appearance/image-required-plugin-i48


You can also try for yourself the free way but depends on theme you have.
In item-post.php look for:
Code: [Select]
             <?php 
                
if(osc_images_enabled_at_items()) { 
                  if(
eps_ajax_image_upload()) { 
                    
ItemForm::ajax_photos();
                  } 
                } 
              
?>


Right underneath that line put:
Code: [Select]
<script type="text/javascript">
    $(document).ready(function(){
$(".qq-upload-button input[name='qqfile']").attr("required", "required");
<?php if(Params::getParam('action') == 'item_edit') { ?>
$(".qq-upload-button input[name='qqfile']").removeAttr("required");         
<?php ?>    
    });
</script>

So it looks like:
Code: [Select]
              <?php 
                
if(osc_images_enabled_at_items()) { 
                  if(
eps_ajax_image_upload()) { 
                    
ItemForm::ajax_photos();
                  } 
                } 
              
?>

<script type="text/javascript">
    $(document).ready(function(){
$(".qq-upload-button input[name='qqfile']").attr("required", "required");
<?php if(Params::getParam('action') == 'item_edit') { ?>
$(".qq-upload-button input[name='qqfile']").removeAttr("required");         
<?php ?>    
    });
</script>
« Last Edit: September 11, 2022, 12:42:33 PM by mwindey »

*

MB Themes

Re: It is obligatory to insert a photo in a new ad.
« Reply #2 on: September 11, 2022, 12:58:15 PM »
@mwindey
Solution is correct, just that plugin do also PHP validation of uploaded inage, but you only propose jquery validation.
Besides that, required inpit must be visible to be required and it is better to ise jquery validation plugin instead of html validation
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • *****
  • 485 posts
Re: It is obligatory to insert a photo in a new ad.
« Reply #3 on: September 11, 2022, 01:39:25 PM »
@MB Themes,

I know the code isn't the best solution and i am not using it myself because off the restrictions in some browsers.
Best solution is always the plugin where validation is more accurate.   ;)
« Last Edit: September 11, 2022, 01:43:29 PM by mwindey »