build/extracted-examples/guides/hack/21-XHP/01-introduction/a_post.inc.hack (29 lines of code) (raw):
// WARNING: Contains some auto-generated boilerplate code, see:
// HHVM\UserDocumentation\MarkdownExt\ExtractedCodeBlocks\FilterBase::addBoilerplate
namespace HHVM\UserDocumentation\Guides\Hack\XHP\Introduction\APost;
use namespace Facebook\XHP\Core as x;
use type Facebook\XHP\HTML\{XHPHTMLHelpers, a, form};
final xhp class a_post extends x\element {
use XHPHTMLHelpers;
attribute string href @required;
attribute string target;
<<__Override>>
protected async function renderAsync(): Awaitable<x\node> {
$id = $this->getID();
$anchor = <a>{$this->getChildren()}</a>;
$form = (
<form
id={$id}
method="post"
action={$this->:href}
target={$this->:target}
class="postLink">
{$anchor}
</form>
);
$anchor->setAttribute(
'onclick',
'document.getElementById("'.$id.'").submit(); return false;',
);
$anchor->setAttribute('href', '#');
return $form;
}
}