function cscf_ContactForm() { $contact = new cscf_Contact(); if ($contact->IsValid()) { if ($contact->SendMail()) { $view = new CSCF_View('message-sent'); $view->Set('heading', cscf_PluginSettings::SentMessageHeading()); $view->Set('message', cscf_PluginSettings::SentMessageBody()); } else { $view = new CSCF_View('message-not-sent'); } return $view->Render(); } //here we need some jquery scripts and styles, so load them here if (cscf_PluginSettings::UseClientValidation() == true) { wp_enqueue_script('jquery-validate'); wp_enqueue_script('cscf-validate'); } //only load the stylesheet if required if (cscf_PluginSettings::LoadStyleSheet() == true) { wp_enqueue_style('cscf-bootstrap'); } $messageSentView = new CSCF_View('message-sent'); $messageSentView->Set('heading', cscf_PluginSettings::SentMessageHeading()); $messageSentView->Set('message', cscf_PluginSettings::SentMessageBody()); $view = new CSCF_View('contact-form'); $view->Set('contact', $contact); $view->Set('message', cscf_PluginSettings::Message()); $view->Set('version', CSCF_VERSION_NUM); $view->Set('confirmEmail', cscf_PluginSettings::ConfirmEmail()); $view->Set('postID', get_the_ID()); $view->Set('messageSentView', $messageSentView); $view->Set('messageNotSentView', new CSCF_View('message-not-sent')); return $view->Render(); }
public function IsValid() { $this->Errors = array(); if ($_SERVER['REQUEST_METHOD'] != 'POST') { return false; } //check nonce if (!wp_verify_nonce($_POST['cscf_nonce'], 'cscf_contact')) { return false; } // email and confirm email are the same if (cscf_PluginSettings::ConfirmEmail()) { if ($this->Email != $this->ConfirmEmail) { $this->Errors['confirm-email'] = __('Sorry the email addresses do not match.', 'cleanandsimple'); } } //email if (strlen($this->Email) == 0) { $this->Errors['email'] = __('Please give your email address.', 'cleanandsimple'); } //confirm email if (cscf_PluginSettings::ConfirmEmail()) { if (strlen($this->ConfirmEmail) == 0) { $this->Errors['confirm-email'] = __('Please confirm your email address.', 'cleanandsimple'); } } //name if (strlen($this->Name) == 0) { $this->Errors['name'] = __('Please give your name.', 'cleanandsimple'); } //message if (strlen($this->Message) == 0) { $this->Errors['message'] = __('Please enter a message.', 'cleanandsimple'); } //email invalid address if (strlen($this->Email) > 0 && !filter_var($this->Email, FILTER_VALIDATE_EMAIL)) { $this->Errors['email'] = __('Please enter a valid email address.', 'cleanandsimple'); } //check recaptcha but only if we have keys if ($this->RecaptchaPublicKey != '' && $this->RecaptchaPrivateKey != '') { $resp = csf_RecaptchaV2::VerifyResponse($_SERVER["REMOTE_ADDR"], $this->RecaptchaPrivateKey, $_POST["g-recaptcha-response"]); if (!$resp->success) { // $this->Errors['recaptcha'] = __('Sorry the code wasn\'t entered correctly please try again.', 'cleanandsimple'); $this->Errors['recaptcha'] = __('Please solve the recaptcha to continue.', 'cleanandsimple'); } } return count($this->Errors) == 0; }
public function IsValid() { $this->Errors = array(); if ($_SERVER['REQUEST_METHOD'] != 'POST') { return false; } //check nonce if (!wp_verify_nonce($_POST['cscf_nonce'], 'cscf_contact')) { return false; } // email and confirm email are the same if (cscf_PluginSettings::ConfirmEmail()) { if ($this->Email != $this->ConfirmEmail) { $this->Errors['confirm-email'] = __('ელ-ფოსტა არ ემთხვევა.', 'cleanandsimple'); } } //email if (strlen($this->Email) == 0) { $this->Errors['email'] = __('ელ-ფოსტა ცარიელია.', 'cleanandsimple'); } //confirm email if (cscf_PluginSettings::ConfirmEmail()) { if (strlen($this->ConfirmEmail) == 0) { $this->Errors['confirm-email'] = __('გთხოვთ, გაიმეოროთ ელ-ფოსტა.', 'cleanandsimple'); } } //name if (strlen($this->Name) == 0) { $this->Errors['name'] = __('სახელი ცარიელია.', 'cleanandsimple'); } //message if (strlen($this->Message) == 0) { $this->Errors['message'] = __('შეტყობინება ცარიელია.', 'cleanandsimple'); } //email invalid address if (strlen($this->Email) > 0 && !filter_var($this->Email, FILTER_VALIDATE_EMAIL)) { $this->Errors['email'] = __('ელ-ფოსტა არასწორია.', 'cleanandsimple'); } //check recaptcha but only if we have keys if ($this->RecaptchaPublicKey != '' && $this->RecaptchaPrivateKey != '') { $resp = cscf_recaptcha_check_answer($this->RecaptchaPrivateKey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { $this->Errors['recaptcha'] = __('კოდი არასწორია. გთხოვთ, სცადოთ თავიდან.', 'cleanandsimple'); } } return count($this->Errors) == 0; }
public function create_fields($args) { $fieldname = $args[0]; switch ($fieldname) { case 'use_recaptcha': $checked = cscf_PluginSettings::UseRecaptcha() == true ? "checked" : ""; ?> <input type="checkbox" <?php echo $checked; ?> id="use_recaptcha" name="<?php echo CSCF_OPTIONS_KEY; ?> [use_recaptcha]"><?php break; case 'load_stylesheet': $checked = cscf_PluginSettings::LoadStyleSheet() == true ? "checked" : ""; ?> <input type="checkbox" <?php echo $checked; ?> id="load_stylesheet" name="<?php echo CSCF_OPTIONS_KEY; ?> [load_stylesheet]"><?php break; case 'recaptcha_public_key': $disabled = cscf_PluginSettings::UseRecaptcha() == false ? "readonly" : ""; ?> <input <?php echo $disabled; ?> type="text" size="60" id="recaptcha_public_key" name="<?php echo CSCF_OPTIONS_KEY; ?> [recaptcha_public_key]" value="<?php echo cscf_PluginSettings::PublicKey(); ?> " /><?php break; case 'recaptcha_private_key': $disabled = cscf_PluginSettings::UseRecaptcha() == false ? "readonly" : ""; ?> <input <?php echo $disabled; ?> type="text" size="60" id="recaptcha_private_key" name="<?php echo CSCF_OPTIONS_KEY; ?> [recaptcha_private_key]" value="<?php echo cscf_PluginSettings::PrivateKey(); ?> " /><?php break; case 'recipient_emails': ?> <ul id="recipients"><?php foreach (cscf_PluginSettings::RecipientEmails() as $key => $recipientEmail) { ?> <li class="recipient_email" data-element="<?php echo $key; ?> "> <input class="enter_recipient" type="email" size="50" name="<?php echo CSCF_OPTIONS_KEY; ?> [recipient_emails][<?php echo $key; ?> ]" value="<?php echo $recipientEmail; ?> "/> <input class="add_recipient" title="Add New Recipient" type="submit" name="add_recipient" value="+"> <input class="remove_recipient" title="Remove This Recipient" type="submit" name="remove_recipient[<?php echo $key; ?> ]" value="-"> </li> <?php } ?> </ul><?php break; case 'confirm-email': $checked = cscf_PluginSettings::ConfirmEmail() == true ? "checked" : ""; ?> <input type="checkbox" <?php echo $checked; ?> id="confirm-email" name="<?php echo CSCF_OPTIONS_KEY; ?> [confirm-email]"><?php break; case 'override-from': $checked = cscf_PluginSettings::OverrideFrom() == true ? "checked" : ""; ?> <input type="checkbox" <?php echo $checked; ?> id="override-from" name="<?php echo CSCF_OPTIONS_KEY; ?> [override-from]"><?php break; case 'email-sender': $checked = cscf_PluginSettings::EmailToSender() == true ? "checked" : ""; ?> <input type="checkbox" <?php echo $checked; ?> id="email-sender" name="<?php echo CSCF_OPTIONS_KEY; ?> [email-sender]"><?php break; case 'from-email': $disabled = cscf_PluginSettings::OverrideFrom() == false ? "readonly" : ""; ?> <input <?php echo $disabled; ?> type="text" size="60" id="from-email" name="<?php echo CSCF_OPTIONS_KEY; ?> [from-email]" value="<?php echo cscf_PluginSettings::FromEmail(); ?> " /><?php break; case 'subject': ?> <input type="text" size="60" id="subject" name="<?php echo CSCF_OPTIONS_KEY; ?> [subject]" value="<?php echo cscf_PluginSettings::Subject(); ?> " /><?php break; case 'sent_message_heading': ?> <input type="text" size="60" id="sent_message_heading" name="<?php echo CSCF_OPTIONS_KEY; ?> [sent_message_heading]" value="<?php echo cscf_PluginSettings::SentMessageHeading(); ?> " /><?php break; case 'sent_message_body': ?> <textarea cols="63" rows="8" name="<?php echo CSCF_OPTIONS_KEY; ?> [sent_message_body]"><?php echo cscf_PluginSettings::SentMessageBody(); ?> </textarea><?php break; case 'message': ?> <textarea cols="63" rows="8" name="<?php echo CSCF_OPTIONS_KEY; ?> [message]"><?php echo cscf_PluginSettings::Message(); ?> </textarea><?php break; case 'theme': $theme = cscf_PluginSettings::Theme(); $disabled = cscf_PluginSettings::UseRecaptcha() == false ? "disabled" : ""; ?> <select <?php echo $disabled; ?> id="theme" name="<?php echo CSCF_OPTIONS_KEY; ?> [theme]"> <option <?php echo $theme == "light" ? "selected" : ""; ?> value="light"><?php _e('Light', 'cleanandsimple'); ?> </option> <option <?php echo $theme == "dark" ? "selected" : ""; ?> value="dark"><?php _e('Dark', 'cleanandsimple'); ?> </option> </select> <?php break; case 'use_client_validation': $checked = cscf_PluginSettings::UseClientValidation() == true ? "checked" : ""; ?> <input type="checkbox" <?php echo $checked; ?> id="use_client_validation" name="<?php echo CSCF_OPTIONS_KEY; ?> [use_client_validation]"><?php break; default: break; } }