Jump to content

How do I require uploading images when posting to a blog?


nguyenvanphu
Go to solution Solved by nguyenvanphu,

Recommended Posts


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?

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

  • Solution
Posted (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 by nguyenvanphu
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.