/** * Method called by the plugin to validate values submitted via a Sellsy's form by a visitor * If values are corrects a prospect is created. * * @param array $selectedFields * @param array $attr of the short code * @param string $formId to ignore request if this request is not destinate to this form * @param array $postValues * * @return null|int id of the prospect if it was created */ public function validateForm(array &$selectedFields, $attr = array(), $formId, $postValues = array()) { if (empty($postValues)) { //Values are not fetched by the plugin, read the superglobal $_POST to get them. $postValues = $_POST; } if (!\is_admin() && isset($postValues['send_wp_sellsy']) && isset($postValues['slswp_nonce_verify_page']) && \wp_verify_nonce($postValues['slswp_nonce_verify_page'], 'slswp_nonce_field')) { //Nonce is valid if (!isset($postValues['formId']) || $postValues['formId'] != $formId) { //Not good form return false; } //Form's value are valid, extract value and create a prospect in Sellsy $postValues = array_intersect_key($postValues, $selectedFields); $body = null; $prospectReturn = $this->sellsyPlugin->createProspect($postValues, $body); if (is_numeric($prospectReturn)) { //Prospect goodly created in the Sellsy account if ('prospectOpportunity' == $this->options[Settings::OPPORTUNITY_CREATION]) { //This plugin is configured to create also an opportunity about this prospect $source = $this->extractSource($attr); //So creates it $this->sellsyPlugin->createOpportunity($prospectReturn, $source, ''); } if (!empty($this->options[Settings::SUBMIT_NOTIFICATION]) && !empty($body)) { //This plugin is configured to send a notification via email, performs it $this->sellsyPlugin->sendMail($body); } return true; } else { return $prospectReturn; } } return false; }