Forms Used only for Event RSVPs

If we create a form that is used only to attach to the RSVP of a specific event, it appears that we have to set the Privacy to “Everyone” or it won’t show up on the event. But if we set it to “Everyone” it will get included in the XML sitemap, and therefore possibly get discovered by search engines. Is there any way around that?

1 Like

Custom module, perhaps?

<?php
public function onOutput($buffer) {
  if ($is_a_form & is_tagged('event-rsvp-form')) { // psudeo
    $_LW->appendMetaTag(array('name'=>'robots', 'content'=>'noindex, nofollow'));
  };
};

Assuming these forms are always “event RSVP forms” and never used as normal forms, you might also be able to:

  1. Read all events with a “RSVP form” field. (read or query)
  2. Gather in an array all of the IDs of the forms used.
  3. Save those form IDs in a caching variable to reference in a foreach/if.

Assuming the “read” can be limited down to events with the field, rather than skimming every event, shouldn’t have too much affect on times. Main issue might be checking both upcoming and past events, to keep older forms hidden. Assuming a centralized model, tags might be best?

Thanks,
Nick

I like the idea of tagging them. Thanks for the idea.

Anyone have a way to check for the existence of a specific tag on a piece of content within a custom module? I thought I had an example but I can’t find anything. And I don’t see anything in the documentation.

I thought I could just use XPHP to do this in the forms template like…

<xphp content="true">
   <if var="has_tag_rsvp"/>
     <content>
        <meta name="robots" content="noindex, nofollow" />
     </content>
</xphp>

…but that doesn’t seem to work. I can’t get that has_tag_ var to do anything in the form details template. XPHP Conditional Functions documentation says <if var="has_tag_foo"/> should work on pages/items.

Does anyone know if I am doing something wrong, or if this isn’t supported?

Hi Jon,

I’m not 100% certain without a bit more research, but I’m pretty sure that metatag handling happens outside of some of the normal HTML workflow in LW, which could be why your has_tag version isn’t working as expected. Sorry about that!

If it helps, here’s some boilerplate code for adding a noindex metatag to all pages.

public function onOutput($buffer) { // on page output
global $_LW;
	
	// add noindex metatag to every page
	$_LW->appendMetaTag(['name'=>'robots', 'content'=>'noindex, nofollow']);
	
};
return $buffer;
}

Maybe something like this could be useful (even just, in a blunt-instrument sense, checking the $buffer for some indicator of your use case) and adding the noindex metatag:

public function onOutput($buffer) { // on page output
global $_LW;
	
	if (stripos($buffer, 'my-markup-used-on-certain-pages')!==false) {
		// add noindex metatag to selected pages
		$_LW->appendMetaTag(['name'=>'robots', 'content'=>'noindex, nofollow']);
	}
};
return $buffer;
}

Thanks @karl . To be honest, I couldn’t get my code to work outside of the <head> either. I tried something like…

<xphp content="true">
   <if var="has_tag_rsvp"/>
     <content>
        <p>This form is tagged "rsvp".</p>
     </content>
</xphp>

…but that didn’t work.

I originally wanted to use a custom module as you described, but thought XPHP would be simpler. If I create a custom module, I would like to append the meta tag based on a tag on the form, but I can’t work out how to determine if a form has a specific tag from within a custom module. Any advice on that?

Sure – I can’t 100% vouch for this code, but I bet something like this would work, added into your module class?

protected function itemHasTag($type, $id, $tag) { // checks if an item is tagged with a specific tag
global $_LW;
if (!empty($type) && !empty($id)) { // if valid type and ID
	if ($table=$_LW->getTableForDataType($type)) { // get the table
		if ($_LW->dbo->query('select', '1', $table, $table.'.id='.(int)$id)
		->innerJoin('livewhale_tags2any', 'livewhale_tags2any.id2='.$table.'.id AND livewhale_tags2any.type='.$_LW->escape($type))
		->innerJoin('livewhale_tags', 'livewhale_tags.id=livewhale_tags2any.id1 AND livewhale_tags.title='.$_LW->escape($tag))
		->exists()
		->run()) { // if the tag is applied
			return true;
		};
	};
};
return false;
}

Then in your other handler (onBeforeOutput or whatnot), you could check
$this->isPrivate('forms', @$LIVE_URL['DETAILS_ID'], 'RSVP');
as a conditional for the tag “RSVP” and conditionally add your noindex meta tag if it returns true.

Thanks. I’ll give that a shot.

I tried a different approach because I found that the livewhale_forms2any table indicates which forms are used in event registrations. So I ended up with this in an onOutput handler…

// Add noindex to forms that are used for event rsvps
if (!empty($_LW->details_module) && $_LW->details_module=='forms') {
    if (
        $_LW->dbo->query(
            'select',
            '1',
            'livewhale_forms2any',
            'livewhale_forms2any.id1='.$_LW->details_id.' AND livewhale_forms2any.type='.$_LW->escape('events_registration')
        )
        ->exists()
        ->run()
    ) {
        $_LW->appendMetaTag(['name'=>'robots', 'content'=>'noindex, nofollow']);
    }
}

It seems to work as I wanted it to. I suppose there is always a chance that a form included in an event rsvp can also stand on its own (and therefore shouldn’t get the meta tag), but we don’t typically do that, so I am not too concerned. At least this way requires no manual tagging of forms and should work to retroactively un-index old rsvp forms as they are recrawled.