We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29201
    • 239 Posts
    As you can see here: http://taiyoagency.com/new-westminster-condo.com/listing.html?listid=6287

    I'm using eform with custom php code to grab a URL parameter and query the database and finally output the Property Address in the form field.

    This all works great without validation however that won't work in this day and age will it? Here is my eform call:

    [!GetCode!]
    			[!eForm? &protectSubmit=`0` &eFormOnBeforeFormParse=`eformGetCode` &formid=`EmailForm` &to=`[email protected]` &from=`((email))` &fromname=`((name))` &subject=`[(site_name)] > [+longtitle+] Viewing Request`  &ccsender=`0` &tpl=`_ContactForm-MLS` &report=`ContactFormReport` &invalidClass=`invalidValue` &requiredClass=`requiredValue` &gotoid=`13`!]


    here is the GetCode snippet:

    <?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
    }
    ?>


    here is the chunk _ContactForm-MLS:

    <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>



    Can anyone help fix this so that I can still have validation and retain the property address?

    Thx!