Osclass forums

Development => Themes => Topic started by: hudson on March 27, 2013, 01:45:30 am

Title: photo is required field
Post by: hudson on March 27, 2013, 01:45:30 am
How can i do what choise photo in item-post.php was required field
Title: Re: photo is required field
Post by: elite1290 on April 17, 2013, 10:37:07 pm
yes I want to find out also, anyone knows how to make upload photo a required field?
Title: Re: photo is required field
Post by: Bettalegend on April 18, 2013, 12:12:03 am
devi modificare il file tem.form.class.php che si trova in oc-includes/osclass/frm/Item.form.class.php e cercare la riga

Code: [Select]
<?php if(osc_images_enabled_at_items()) { ?>
                "photos[]": {
                    accept: "<?php echo osc_allowed_extension(); ?>"
                },

e sostituirla così:

Code: [Select]
<?php if(osc_images_enabled_at_items()) { ?>
                "photos[]": {
required: true,
                    accept: "<?php echo osc_allowed_extension(); ?>"
                },

------------------------------------------------------------------------------------------------

you have to edit the file that is located in oc-includes/osclass/frm/Item.form.class.php and look for the line

Code: [Select]
<?php if(osc_images_enabled_at_items()) { ?>
                "photos[]": {
                    accept: "<?php echo osc_allowed_extension(); ?>"
                },

and replace as follows:

Code: [Select]
<?php if(osc_images_enabled_at_items()) { ?>
                "photos[]": {
required: true,
                    accept: "<?php echo osc_allowed_extension(); ?>"
                },
Title: Re: photo is required field
Post by: AdsGig on August 31, 2013, 02:55:43 pm
This validation works for new ads, but if I edit an existing ad with pictures it is still validating. 
How can we resolved this?
Title: Re: photo is required field
Post by: byteGator on August 31, 2013, 05:30:48 pm
This validation works for new ads, but if I edit an existing ad with pictures it is still validating. 
How can we resolved this?

Copy function that contain that javascript at item.form.class. then use modified class for new post and unmodified for edited post.
Title: Re: photo is required field
Post by: AdsGig on September 01, 2013, 11:15:13 am
This validation works for new ads, but if I edit an existing ad with pictures it is still validating. 
How can we resolved this?

Copy function that contain that javascript at item.form.class. then use modified class for new post and unmodified for edited post.

Thanks @byteGator for the response I was thinking the same but how to implement it? :)
Title: Re: photo is required field
Post by: AdsGig on October 12, 2013, 09:11:21 am
seems to be an old topic but how to solve this ?
Title: Re: photo is required field
Post by: shamim_biplob on October 13, 2013, 01:42:26 am
how can i add server side validation? not only for photo but also if i add any field?
i am adding rules in itemAction.php but i dont kno why it is not working. client side working well.
Title: Re: photo is required field
Post by: elite1290 on December 08, 2013, 11:39:05 pm
seems to be an old topic but how to solve this ?

anyone has solution on how to implement for edit ad?
Title: Re: photo is required field
Post by: elite1290 on December 10, 2013, 11:15:07 am
there are 2x file post-item.php and edit-item.php in the theme folder,

and post-item reference
to oc-includes/osclass/frm/Item.form.class.php (say photojava script1)

and edit-item reference
to oc-includes/osclass/frm/Item.form.class.php (say photojava script2) <- has copy and paste

now question is what should be the code for photojava script1 and photojava script2?

photojava script1 we leave it original
photojava script2 what should be the modified code? so that when user edit ad it will not validate
the photojava script2 to check photo as required field, anyone has any clue please advice?
Title: Re: photo is required field
Post by: kokobaibaicom on February 03, 2014, 10:57:25 pm
can anyone clarify this? thanks a bunch!
Title: Re: photo is required field
Post by: kokobaibaicom on February 05, 2014, 08:31:23 pm
i am dying for a solution to this image required. I'm sorry if its a bother
Title: Re: photo is required field
Post by: shatadon on January 15, 2017, 05:19:55 am
I've used some Jquery to solve this issue. Where the image is required on new post but not required on edit post.

Currently using V3.7.1 Bender theme

Edit file: /oc-content/themes/bender/item-post.php

LOOK FOR:
Code: [Select]
<?php if( osc_images_enabled_at_items() ) {
        
ItemForm::ajax_photos();
?>


AND ADD RIGHT AFTER:
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 RESULT SHOULD LOOK LIKE:
Code: [Select]
<?php if( osc_images_enabled_at_items() ) {
        
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>

PLEASE NOTE THAT IF YOU ARE USING ANOTHER THEME, THE REFERENCE .qq-upload-button input[name='qqfile'] MAY BE DIFFERENT

WE WILL ALSO NEED TO ADD THIS CODE FOR IOS SUPPORT (place in either header.php or footer.php)
Code: [Select]
<script>
$(document).ready(function() {
    if(isAppleDevice() === true) {
    $("body.item.item-post button[type='submit']").on('click', function(event) {          
if($("ul.qq-upload-list li").length === 0) {     
event.preventDefault();
alert("Opps, it seems you forgot to upload some pictures!");
$('body').animate({
scrollTop: $("input[name='qqfile']").offset().top
}, 500);
$(".qq-upload-button").attr("style","border: 6px solid #ffad00;");
}   
    });
    }
 });
 
function isAppleDevice(){
    return (
        (navigator.userAgent.toLowerCase().indexOf("ipad") > -1) ||
        (navigator.userAgent.toLowerCase().indexOf("iphone") > -1) ||
        (navigator.userAgent.toLowerCase().indexOf("ipod") > -1)
    );
}

</script>

AGAIN THE ELEMENTS I TARGET IN THE CODE ABOVE MAY VARY BASED ON TEMPLATE.
Title: Re: photo is required field
Post by: sha_bd on April 07, 2017, 01:29:39 pm
Hi shatadon,

You method works great! But one thing i like to do is...changing the validation message position.

Right now as per your method the image input filed become required but the default error message shows very left of webpage.

How to place the image required field error message at bottom of the image field or very close to image field.

You can see the screenshot for better understanding..

Thanks
Title: Re: photo is required field
Post by: aspetruk on July 04, 2017, 05:56:10 pm
This way it works, BUT it allows you to delete photos during editing and leave an ad without photos
I had to torment myself, but still the modified function:

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') { ?>
            if ($("li.qq-upload-success").length != 0){
                $(".qq-upload-button input[name='qqfile']").removeAttr("required");
            }
        <?php ?>
        $('a.qq-upload-delete').click( function(e) {e.preventDefault();
            if ($("li.qq-upload-success").length <= 1) {
                $(".qq-upload-button input[name='qqfile']").attr("required", "required");
            }
        return false; } );
        $('.imagebox').on('click', '.qq-upload-delete', function (){
            if ($("li.qq-upload-success").length <= 1) {
                $(".qq-upload-button input[name='qqfile']").attr("required", "required");
            }
        });
    });
</script>
Title: Re: photo is required field
Post by: pixelpadre on December 16, 2018, 11:16:16 pm
I think a really easy way is create a MANDATORY custom field CHECK BOX that forces the user acknowledge that listings without pics will be deleted. This method is something short of a slap on the back of their heads.

Title: Re: photo is required field
Post by: Lissandragaren3 on December 31, 2018, 12:20:55 pm
devi modificare il file tem.form.class.php che si trova in oc-includes/osclass/frm/Item.form.class.php e cercare la riga

Code: [Select]
<?php if(osc_images_enabled_at_items()) { ?>
                "photos[]": {
                    accept: "<?php echo osc_allowed_extension(); ?>"
                },

e sostituirla così:

Code: [Select]
<?php if(osc_images_enabled_at_items()) { ?>
                "photos[]": {
required: true,
                    accept: "<?php echo osc_allowed_extension(); ?>"
                },

------------------------------------------------------------------------------------------------

you have to edit the file that is located in oc-includes/osclass/frm/Item.form.class.php and look for the line

Code: [Select]
<?php if(osc_images_enabled_at_items()) { ?>
                "photos[]": {
                    accept: "<?php echo osc_allowed_extension(); ?>"
                },

and replace as follows:

Code: [Select]
<?php if(osc_images_enabled_at_items()) { ?>
                "photos[]": {
required: true,
                    accept: "<?php echo osc_allowed_extension(); ?>"
                },
Thank you bro.