Customising the review form

Hello all! I went on and tried to customize the review form semi-successfully.
I was able to add fields to the form, still need to tweak CSS so that at least the labels show before the fields instead of on top, the issue I am having is that the custom fields are not saved into the database.
In addition, the review now is not shown on the listing page.
I have followed the video on customizing forms (it uses the message form as an example) and the documentation as much as I was able to figure it out.
Here is my code, added to the functions.php file.


//Customization of Review form

add_filter(
	'hivepress/v1/forms/review_submit',
	function( $form ) {
		$form['fields']['clicks_ordered'] = [
			'label'	=> 'Clicks Ordered',
			'type'	=> 'number',
			'min_value'	=> 0,
			'required'	=> true,
			'_order'	=> 10,
		];

		$form['fields']['clicks_delivered'] = [
			'label'	=> 'Clicks Delivered',
			'type'	=> 'number',
			'min_value'	=> 0,
			'required'	=> true,
			'_order'	=> 11,
		];
		
		$form['fields']['tier_one'] = [
			'label'	=> 'T1 %',
			'type'	=> 'number',
			'min_value'	=> 0,
			'required'	=> true,
			'_order'	=> 12,
		];

		$form['fields']['optins'] = [
			'label'	=> 'Opt-in Rate %',
			'type'	=> 'number',
			'min_value'	=> 0,
			'required'	=> true,
			'_order'	=> 13,
		];

		$form['fields']['sales'] = [
			'label'	=> 'Number of sales',
			'type'	=> 'number',
			'min_value'	=> 0,
			'required'	=> true,
			'_order'	=> 14,
		];
		
		if ( isset( $form['fields']['text'] ) ) {
			$form['fields']['text']['label'] = 'Comments';
		}
		return $form;
	}
);

I am guessing I am missing some “definition” of the fields somewhere. Any help is very much appreciated.

1 Like

Please try this PHP snippet. In this way, adding other fields to the form and saving their value after submitting the form is possible.

add_filter(
	'hivepress/v1/models/review',
	function($fields){
		$fields['fields']['clicks_ordered'] = [
			'label'	=> 'Clicks Ordered',
			'type'	=> 'number',
			'min_value'	=> 0,
			'required'	=> true,
			'_order'	=> 10,
		];
		
		return $fields;
	},
	1000
);

add_filter(
	'hivepress/v1/forms/review_submit',
	function($fields){
		$fields['fields']['clicks_ordered'] = [
			'_order'	=> 30,
		];
		
		return $fields;
	},
	1000
);

The result is the same, the comment is saved in the database, the other fields are not.
Upon approval of the comment, it will not show in the front under the user listing.
Code:

//Customization of Review form

add_filter(
	'hivepress/v1/models/review',
	function( $form ) {
		$form['fields']['clicks_ordered'] = [
			'label'	=> 'Clicks Ordered',
			'type'	=> 'number',
			'min_value'	=> 0,
			'required'	=> true,
			'_order'	=> 10,
		];

		$form['fields']['clicks_delivered'] = [
			'label'	=> 'Clicks Delivered',
			'type'	=> 'number',
			'min_value'	=> 0,
			'required'	=> true,
			'_order'	=> 11,
		];
		
		$form['fields']['tier_one'] = [
			'label'	=> 'T1 %',
			'type'	=> 'number',
			'min_value'	=> 0,
			'required'	=> true,
			'_order'	=> 12,
		];

		$form['fields']['optins'] = [
			'label'	=> 'Opt-in Rate %',
			'type'	=> 'number',
			'min_value'	=> 0,
			'required'	=> true,
			'_order'	=> 13,
		];

		$form['fields']['sales'] = [
			'label'	=> 'Number of sales',
			'type'	=> 'number',
			'min_value'	=> 0,
			'required'	=> true,
			'_order'	=> 14,
		];
		
		if ( isset( $form['fields']['text'] ) ) {
			$form['fields']['text']['label'] = 'Comments';
		}
		return $form;
	},
	1000
);

add_filter(
	'hivepress/v1/forms/review_submit',
	function($fields){
		$fields['fields']['clicks_ordered'] = [
			'_order'	=> 30,
		];
		
		$fields['fields']['clicks_delivered'] = [
			'_order'	=> 31,
		];
		
		$fields['fields']['tier_one'] = [
			'_order'	=> 32,
		];

		$fields['fields']['optins'] = [
			'_order'	=> 33,
		];

		$fields['fields']['sales'] = [
			'_order'	=> 34,
		];
		
		return $fields;
				
	},
	1000
);

I realized the _order values did not match on both filters and used the same order. Now the testimonial shows, but again, without all the custom fields, just the rating and comments are shown

I commented out my own function, and just to make sure, I copied your functions and used them as you posted them. The results are the same, the extra fields are not saved to the table and they are not shown in the review block.
I realize this should be simpler, as the video I watched seems to work just fine by modifying the comments, but for some reason, I still think there is something missing.

Sorry for the misunderstanding. Please try this PHP snippet instead. In this way, adding other fields to the form and saving their value after submitting the form is possible. This code snippet only adds fields to the review submit form and saves their values in the database.

add_filter(
	'hivepress/v1/models/review',
	function($fields){
		$fields['fields']['clicks_ordered'] = [
			'label'	=> 'Clicks Ordered',
			'type'	=> 'number',
			'min_value'	=> 0,
			'required'	=> true,
			'_external' => true,
			'_order'	=> 10,
		];
		
		return $fields;
	},
	1000
);

add_filter(
	'hivepress/v1/forms/review_submit',
	function($fields){
		$fields['fields']['clicks_ordered'] = [
			'_order'	=> 30,
		];
		
		return $fields;
	},
	1000
);

It requires advanced customization if you want to show their values in the single review block on the listing page. Please use this PHP code snippet as an example. It shows the field clicks_ordered in the review block

add_filter(
	'hivepress/v1/templates/review_view_block/blocks',
	function($blocks, $template){
		$review = $template->get_context('review');
		
		if(!$review){
			return $blocks;
		}
		
		return hivepress()->template->merge_blocks(
			$blocks,
			[
				'review_content' => [
					'blocks' => [
						'custom_clicks_ordered' => [
							'type' => 'content',
							'content' => '<strong>Clicks ordered field content:</strong> '.$review->get_clicks_ordered(),
							'_order' => 30,
						]	
					],
				],
			],
		);
	},
	1000,
	2
);

This works perfectly, the _external parameter was missing.
With this problem fixed, I wonder if there is a way to modify the submit review form in a way that the fields are displayed in 2 columns? The modal form is too long with the additional fields.
Thank you for your help, much appreciated!

It is possible, but unfortunately, there’s no simple code snippet. It would require a custom implementation. If customizations beyond the available features are required for your site, please consider hiring someone for custom work https://fvrr.co/32e7LvY

It would seem to me that it is simply css customization. Wouldn’t?

In case anyone needs the solution for the modal width, here is what I did:

.fancybox-slide .fancybox-content {
	width: 700px;
}

Of course, this changes the width of all the modal forms, but it works for me (they actually look better wider)

I apologize if it would be better to open a new topic, but since they are related, I thought I would just ask here. Is there a way to show “No reviews yet, Submit a review” (submit a review being a link to open the review form) in the review list when no reviews have been posted yet?

Hi,

Sorry, there’s no simple code snippet for this, it would require a custom implementation. If customizations beyond the available features are required for your site, please consider hiring someone for custom work https://fvrr.co/32e7LvY

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