<?php
function eformGetCode(&$fields, &$templates) {
global $modx; // Access to DocumentParser
// get parameter from url
$mail_id = isset($_REQUEST['listid']) ? intval($_REQUEST['listid']) : 0;
$evt =& $modx->event; // The Snippet call event (not eFormOnBeforeFormParse event)
// Replicate $isPostBack variable
$validFormId = ($evt->params['formid'] == $_POST['formid']);
$isPostBack = ($validFormId && count($_POST) > 0); // (bool)true if the form is being updated
if (!$isPostBack && $mail_id > 0) {
// Check for NOT postback, cuz we want to populate an empty form
// Also, make sure we have an id greater than 0
$rs = $modx->db->select(
'`Address`, `ListingID`', // fields to get
'mls_listings', // custom table
'ListingID='.$mail_id // Select by id
);
$row = $modx->db->getRow($rs); // Get the single row
if (!empty($row)) // Does the row have data?
$fields = $row; // Copy the data over to the fields variable
} else {
// The form has beed posted, let's not disturb the data.
}
return true; // A value of false will stop the eForm parser
}
?>
<a name="contact"></a>
[+validationmessage+]<br/>
<form method="post" action="[~[*id*]~]?listid=[+ListingID+]#contact" id="EmailForm" name="EmailForm">
<div class="field">
<input type="text" name="name" id="cfName" onclick="this.value='';" onfocus="this.select()"
onblur="this.value=!this.value?'':this.value;" value="" class="input text" placeholder="Your name" class="contact_field" eform="Your Name::1:" />
</div>
<div class="field">
<input type="text" name="email" id="cfEmail" onclick="this.value='';" placeholder="Your e-mail" onfocus="this.select()" onblur="this.value=!this.value?'':this.value;" eform="Email Address:email:1" value="" class="input text" />
</div>
<div class="field">
<input value="[+Address+]" name="subject" id="cfRegarding" placeholder="[+Address+]" eform="Property::0">
</div>
<div class="field">
<input name="contact" id="cfContact" class="button full th-brown" value="Send" type="submit" />
</div>
</form>