public function renderContactForm() { if ($this->getAvailability() == 'reference') { return false; } $form = new \casawp\Form\ContactForm(); $sent = false; $customerid = get_option('casawp_customerid'); $publisherid = get_option('casawp_publisherid'); $email = get_option('casawp_email_fallback'); if ($this->getFieldValue('seller_org_customerid', false)) { $customerid = $this->getFieldValue('seller_org_customerid', false); } if ($this->getFieldValue('seller_inquiry_person_email', false)) { $email = $this->getFieldValue('seller_inquiry_person_email', false); } if (get_option('casawp_inquiry_method') == 'casamail') { //casamail if (!$customerid || !$publisherid) { return '<p class="alert alert-danger">CASAMAIL MISCONFIGURED: please define a provider and publisher id <a href="/wp-admin/admin.php?page=casawp&tab=contactform">here</a></p>'; } } else { if (!$email) { return '<p class="alert alert-danger">EMAIL MISCONFIGURED: please define a email address <a href="/wp-admin/admin.php?page=casawp&tab=contactform">here</a></p>'; } } if ($_POST) { $filter = $form->getFilter(); $form->setInputFilter($filter); $form->setData($_POST); if ($form->isValid()) { $validatedData = $form->getData(); $sent = true; if (isset($_POST['email']) && $_POST['email']) { //SPAM } else { //add to WP for safekeeping $post = array('post_type' => 'casawp_inquiry', 'post_content' => $form->get('message')->getValue(), 'post_title' => wp_strip_all_tags($form->get('firstname')->getValue() . ' ' . $form->get('lastname')->getValue() . ': [' . ($this->getFieldValue('referenceId') ? $this->getFieldValue('referenceId') : $this->getFieldValue('casawp_id')) . '] ' . $this->getTitle()), 'post_status' => 'private', 'ping_status' => false); $inquiry_id = wp_insert_post($post); foreach ($form->getElements() as $element) { if (!in_array($element->getName(), array('message'))) { add_post_meta($inquiry_id, 'sender_' . $element->getName(), $element->getValue(), true); } } add_post_meta($inquiry_id, 'casawp_id', $this->getFieldValue('casawp_id'), true); add_post_meta($inquiry_id, 'referenceId', $this->getFieldValue('referenceId'), true); if (get_option('casawp_inquiry_method') == 'casamail') { //casamail $data = $_POST; $data['email'] = $_POST['emailreal']; $data['provider'] = $customerid; $data['publisher'] = $publisherid; $data['lang'] = substr(get_bloginfo('language'), 0, 2); $data['property_reference'] = $this->getFieldValue('referenceId'); //direct recipient emails if (get_option('casawp_casamail_direct_recipient') && $this->getFieldValue('seller_inquiry_person_email', false)) { $data['direct_recipient_email'] = $this->getFieldValue('seller_inquiry_person_email', false); } $data_string = json_encode($data); $ch = curl_init('http://onemail.ch/api/msg'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string))); curl_setopt($ch, CURLOPT_USERPWD, "casawp:MQX-2C2-Hrh-zUu"); $result = curl_exec($ch); $json = json_decode($result, true); if (isset($json['validation_messages'])) { wp_mail('*****@*****.**', 'casawp casamail issue', print_r($json['validation_messages'], true)); return '<p class="alert alert-danger">' . print_r($json['validation_messages'], true) . '</p>'; } //header("Location: /anfrage-erfolg/"); //die('SUCCESS'); } else { } } } else { $messages = $form->getMessages(); } } else { $form->get('message')->setValue(__('I am interested concerning this property. Please contact me.', 'casawp')); } //$form->bind($this->queryService); return $this->render('contact-form', array('form' => $form, 'offer' => $this, 'sent' => $sent)); }