nguyenvanphu Posted July 13 Share Posted July 13 I am using Sngine 3.11 How to force users to upload images when posting to blogs (because there is no forced upload feature by default) I used required attribute but it didn't work <div class="row form-group"> <label class="col-md-2 form-label"> {__("Cover")} </label> <div class="col-md-10"> <div class="x-image"> <button type="button" class="btn-close x-hidden js_x-image-remover" title='{__("Remove")}'> </button> <div class="x-image-loader"> <div class="progress x-progress"> <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div> </div> </div> <i class="fa fa-camera fa-lg js_x-uploader" data-handle="x-image"></i> <input type="hidden" class="js_x-image-input" name="cover" required> </div> </div> </div> Can you help me? Quote Link to comment Share on other sites More sharing options...
requinix Posted July 13 Share Posted July 13 Hidden inputs can't be required. They're hidden. The user can't do anything with them. Assuming you have some sort of Javascript to read a file and put its contents into that input, which is weird because it's reinventing the wheel, then use more Javascript to prevent the user from submitting the form until they've chosen the file. 1 Quote Link to comment Share on other sites More sharing options...
nguyenvanphu Posted July 14 Author Share Posted July 14 20 hours ago, requinix said: Hidden inputs can't be required. They're hidden. The user can't do anything with them. Assuming you have some sort of Javascript to read a file and put its contents into that input, which is weird because it's reinventing the wheel, then use more Javascript to prevent the user from submitting the form until they've chosen the file. Thank you Ad for teaching me. I fix it: <input type="file" class="js_x-image-input" name="cover" required> right admin? I don't know how to write Javascript Can you guide me please? Quote Link to comment Share on other sites More sharing options...
requinix Posted July 14 Share Posted July 14 If you've fixed it then you don't need Javascript... 1 Quote Link to comment Share on other sites More sharing options...
nguyenvanphu Posted July 14 Author Share Posted July 14 1 hour ago, requinix said: If you've fixed it then you don't need Javascript... Thanks, I fixed it but it doesn't work Quote Link to comment Share on other sites More sharing options...
requinix Posted July 14 Share Posted July 14 If you "fixed it" but it doesn't work then you didn't fix it. That input type=file can work, I would think, however it will require changing some number of other things - I can't say exactly what since it's complicated and it will depend a lot on other things (which you haven't shown) but it can work. Either that, or go back to what you had before and do what I originally said about using Javascript to prevent the form from being submitted. Again, I can't say exactly how since it depends on things you haven't posted, but the principle is very simple: when the form is being/is about to be submitted, check that there is a value for that cover "file", and if not then stop the form from submitting and tell the user they missed a step. 1 Quote Link to comment Share on other sites More sharing options...
Solution nguyenvanphu Posted July 15 Author Solution Share Posted July 15 (edited) 4 hours ago, requinix said: If you "fixed it" but it doesn't work then you didn't fix it. That input type=file can work, I would think, however it will require changing some number of other things - I can't say exactly what since it's complicated and it will depend a lot on other things (which you haven't shown) but it can work. Either that, or go back to what you had before and do what I originally said about using Javascript to prevent the form from being submitted. Again, I can't say exactly how since it depends on things you haven't posted, but the principle is very simple: when the form is being/is about to be submitted, check that there is a value for that cover "file", and if not then stop the form from submitting and tell the user they missed a step. Doing what you just instructed is too difficult for me. But I will slowly study what you say. Thank you for your enthusiasm in helping me. You are wonderful !! Edited July 15 by nguyenvanphu Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.