Skip to Content
Menu

feedback()

Add a simple feedback system (with optional form) to pages to understand which pages are helpful and which need improvement.

PHP July 14, 2021

Usage

PHP
nebula()->feedback($form_id);

Parameters

$form_id
(Optional) (Integer) The CF7 form ID
Default: None

Parameter Notes

The Contact Form 7 form should be created specifically for user feedback. It is not recommended to try to re-use another contact form.

If a CF7 form ID is not provided, this system will simply log “Helpful” or “Not Helpful” in Google Analytics with no additional input from the user.

Request or provide clarification »

Examples

Only log feedback in Google Analytics (no form)

PHP
<?php nebula()->feedback(); ?>

Get use feedback with a CF7 form

PHP
<?php nebula()->feedback(1234); ?>

Add the feedback system to all posts and pages (including custom post types) from the functions file with a single snippet placement (no need to edit each template)

PHP
add_action('loop_end', 'show_nebula_feedback_system'); //At the end of every loop (be sure to test this as it may trigger more than you expect!)
add_action('nebula_no_search_results', 'show_nebula_feedback_system'); //On "no search results" pages
add_action('nebula_404_content', 'show_nebula_feedback_system'); //On 404 pages
function show_nebula_feedback_system(){
    if ( nebula()->is_admin_page() ){ //Ignore WP admin pages
        return false;
    }

    if ( is_page(123) || is_page(456) || is_page(789) ){ //Ignore specific pages if desired
        return false;
    }

    if ( is_front_page() ){ //Ignore the home page
        return false;
    }

    if ( !is_singular() && !is_search() && !is_404() ){ //Ignore non-single posts/pages, but allow search and 404 templates
        return false;
    }

    nebula()->feedback(1234); //Show the feedback system with a form
}

Demo


Use this in the Form editor (customize as needed):

<div class="nebula-validate">
	<div class="nebula-form-group">
		<label class="form-label" for="message">How can we improve?</label>
		[textarea message id:message class:form-control class:nebula-validate-textarea placeholder "Write your feedback here"]
		<div class="invalid-feedback">A feedback message is required to submit this form.</div>
	</div>
	<div class="nebula-form-group">
		<label class="form-label" for="email">Email Address <small class="text-muted"><em>(optional)</em></small></label>
		[email email id:email class:form-control class:nebula-validate-email class:crm-email_address autocomplete:email]
		<div class="invalid-feedback">Please check that you have entered a valid email address.</div>
		<small class="form-text text-muted">Enter your email address if you would like a response.</small>
	</div>
	[submit class:btn class:btn-brand class:btn-sm class:notable-form "Send Feedback"]
</div>

Use this in the Mail Message Body (customize as needed):

Email (optional): [email]

Feedback:
[message]


--
This e-mail was sent from a CF7 form on [_date] at [_time] from [_url]

[debuginfo]

If using this function within the post loop, consider using the following Subject Line in the CF7 Mail tab:

User feedback submitted for [_post_title]

Additional Notes

If using a CF7 form, be sure to place the feedback form inside of the post loop if you want to use the post-related special mail tags (such as [_post_title])!

Contact Form 7 Special Mail Tags »

The email field should be optional! The purpose of this form is not lead generation, but improving user experience. CF7 may flag a configuration issue if the reply-to setting exists with an optional email field. It is recommended to simply remove the reply-to for this feedback form.

You may choose not to have this send emails, but instead log them to the database using any CF7 database plugin (one is bundled with Nebula, but you must activate it yourself).

Was this page helpful? Yes No


    A feedback message is required to submit this form.

    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Functions.php on line 1924.

    No Hooks

    This function does not have any filters or actions available. Request one?
    PHP
            public function feedback($form_id=false){
                ?>
                    <div id="nebula-feedback-system" class="<?php echo ( empty($form_id) )? 'no-feedback-form' : 'has-feedback-form'; ?>">
                        <div id="nebula-feedback-question" class="">
                            <span><?php echo __('Was this page helpful?', 'nebula'); ?></span> <a id="nebula-feedback-yes" class="nebula-feedback-button" href="#"><i class="fas fa-fw fa-thumbs-up"></i> <?php echo __('Yes', 'nebula'); ?></a> <a id="nebula-feedback-no" class="nebula-feedback-button" href="#"><i class="fas fa-fw fa-thumbs-down"></i> <?php echo __('No', 'nebula'); ?></a>
                        </div>
    
                        <?php if ( !empty($form_id) ): ?>
                            <div id="nebula-feedback-form-container" data-form-id="<?php echo $form_id; ?>">
                                <?php echo do_shortcode('[contact-form-7 id="' . $form_id . '"]'); ?>
                            </div>
                        <?php endif; ?>
    
                        <div id="nebula-feedback-thanks">
                            <span><?php echo __('Thank you for your feedback!', 'nebula'); ?></span>
                        </div>
                    </div>
                <?php
            }
    

    Override

    This function can not be short-circuited with an override filter. Request one?