Make image required for request

Hello, when you go in listing form and upload images, there is arrow indication on image to move it and also cross to delete it, but on the request form, this doesn’t happen for me and only the move arrow is there, no delete. Is there any snippet or css for it?

Also second question, sometimes when you close and re-open the add listing form, some stuff like category or title stays filled and uploaded images sometimes stay there, sometimes don’t. Is there any way to never save anything in both request and listing form after closing it and re-opening? So it must be all filled again. Thank you

Hi,

Can you please clarify whether you will add a PHP snippet that makes the image required request? If so, then you won’t be able to remove the first image because it is always required. Also, as another reason, please check if you have added a custom attribute that is required, then it works the same way.

On your other question, unfortunately, there is no simple solution for this, so it would require a custom implementation because auto-draft will always be there because uploaded files are always attached in WordPress, so this is the draft that is needed. Also, please note that auto-drafts are automatically deleted every 24 hours, there may be a solution to do it more often, but you also need to check it additionally using a custom code (and the addition form will be completely reset when you finish the addition process).

​I hope this is helpful to you.

Hey andrii,

It doesn’t matter if I add more than 1 image. I tried 4 and the image still doesn’t show remove button, just move. Images are not required in this form, but would love to add some snippet for that also. It’s okay if the form doesn’t clear itself more often, but now those images just stays there and don’t go away and I have no way of removing them. Attached image for better understanding of what I mean. On listing form there is a remove button above move button when uploading images, but not in request form.

Here is the Listing form image submit. In listing form there are at least 3 images required, and even the first one and even if it’s the only one can be removed, so it shouldn’t collide with that function.

And because in the request form there is no way of removing images because of missing cross, they stay there until you submit the request with no other way for user to remove them.

Hi,

I see. Please send temporary WP access to support@hivepress.io with details for reproducing this issue, and we’ll check it (please send only the link, without login and password). You can create a temporary access link using this plugin Temporary Login Without Password – WordPress plugin | WordPress.org.

Sent, thanks.

Hi,

I see. Please use this PHP snippet instead of the one you added earlier to make the request image required:

add_filter(
	'hivepress/v1/forms/request_update/errors',
	function( $errors, $form ) {
		$request = $form->get_model();

		if ( $request && ! $request->get_image__id() ) {
			$errors[] = 'Please upload at least one image.';
		}

		return $errors;
	},
	100,
	2
);

add_filter(
	'hivepress/v1/forms/request_update',
	function( $form ) {
		$form['fields']['images']['statuses']['optional'] = null;

		return $form;
	},
	1000
);

​I hope this is helpful to you.

Thank you, that’s okay for second problem, but the main problem still remains. Still can’t delete images in that form. And this post isn’t about “Make image required for request”. It’s about removing loaded/attached images in request form.

Hi,

You didn’t disable the previous PHP snippet, so you couldn’t delete the image. Now everything seems to be working correctly.

It works now. For anyone with the same issue, rewriting the snippet doesn’t work. I had to create completely new one and delete the old one. Thank you for help andrii

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.