css 逐步返工marvelouswololo的联系表格代码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css 逐步返工marvelouswololo的联系表格代码相关的知识,希望对你有一定的参考价值。

<?php
/*
Plugin Name: Marvelous Wololo Contact Form
Plugin URI: https://gist.github.com/MarvelousWololo/fb6488b1e9ad92c6c8d6fd91ed8b55d4
Description: Adds a custom contact form shortcode
Version: 0.0.1
Author: Marvelous Wololo
Author URI: https://reddit.com/user/MarvelousWololo
*/

// inspired by https://premium.wpmudev.org/blog/how-to-build-your-own-wordpress-contact-form-and-why/

function mwcf_enqueue_scripts() {
	wp_register_style( 'mwcf-stylesheet', plugins_url( 'styles.css', __FILE__ ), array(), '0.0.1', 'all' );
}
add_action( 'wp_enqueue_scripts', 'mwcf_enqueue_scripts' );

function mwcf_log_error ($m) {
	$error_logging_enabled = false;
	if( $error_logging_enabled ) {
		error_log($m);
	}
}

function mwcf_validate_inputs () {
  $name = '';
  $email = '';
  $message = '';
  if( !empty( $_POST['mwcf_message_name'] ) ) {
    $name = trim( $_POST["mwcf_message_name"] );
    $name = str_replace(array("<", ">", "\n", "\r", ","), '', $name); // get rid of mail header control characters in name
  }
  if( !empty( $_POST['mwcf_message_email'] ) ) {
    $email = trim( $_POST["mwcf_message_email"] );
  }
  if( !empty( $_POST['mwcf_message_text'] ) ) {
    $message = trim( $_POST["mwcf_message_text"] );
    $message = strip_tags($message);
  }
  
  $error_messages = array();

  if (empty($name))) {
    array_push($error_messages, "Name is required");
  }

  if (empty($email)) {
    array_push($error_messages, "Email is required");
  } else {
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      array_push($error_messages, "Email is invalid");
    }
  }

  if (empty($message)) {
    array_push($error_messages, "Message is required");
  }

  return array(
    "error_messages" => $error_messages,
    "name" => $name,
    "email" => $email,
    "message" => $message
  );
}

function mwcf_render_shortcode( $atts, $content = '' ) {
  wp_enqueue_style('mwcf-stylesheet');
  // the second half of this check verifies that our honeypot field is empty
  $form_submitted = isset($_POST["mwcf_submit"]) && empty($_POST["mwcf_website"]);
  $name = '';
  $email = '';
  $message = '';
  if ($form_submitted) {
    $inputs = mwcf_validate_inputs();
    $error_messages = $inputs["error_messages"];

    if (empty($error_messages)) {
      mwcf_log_error("form is okay");

      $name = $inputs["name"];
      $email = $inputs["email"];
      $message = $inputs["message"];

      $admin_email = get_option("admin_email");
      $blog_name = get_bloginfo("name"); 
      $subject = "Someone sent a message from $blog_name"; 
      $headers = array(
        "Reply-To: $name <$email>",
      );

      $sent = wp_mail($admin_email, $subject, $message, $headers);

      if ($sent) {
        mwcf_log_error("marvelous wololo contact form sent email");

        $success_message = "Email sent";
      } else {
        mwcf_log_error("marvelous wololo contact form couldn't send email");

        $error_message = "Sorry, we couldn't send your message now. Please, try again later";

        $error_messages = array($error_message);
      }
    }
  }
  
  ob_start();
  ?>

  <div class="mwcf_contact_form">
    <?php
      if (!empty($error_messages)) {
        foreach ($error_messages as $error) {
          echo '<p class="mwcf_error">' . $error . '</p>';
        }
      }

      if (!empty($success_message)) {
        echo '<p class="mwcf_success">' . $success_message . '</p>';
      }
    ?>
    <form action="#" method="post">
      <label>Name: <span class="req">*</span>
        <input type="text" name="mwcf_message_name" value="<?php echo esc_attr( $name ); ?>" required>
      </label>
      <label>Email: <span class="req">*</span>
        <input type="email" name="mwcf_message_email" value="<?php echo esc_attr( $email ); ?>" required>
      </label>
      <?php // start antispam honeypot. this field will be hidden. if it is filled, the form will be rejected. ?>
      <label class="hp-field">Website:
        <input type="url" name="mwcf_website" value="" autocomplete="off">
      </label>
      <?php // end anti-spam honeypot ?>
      <label>Message: <span class="req">*</span>
        <textarea name="mwcf_message_text" required><?php echo esc_textarea( $message ); ?></textarea>
      </label>
      <input type="submit" name="mwcf_submit">
    </form>
  </div>
  <?php
  return ob_get_clean();
}

add_shortcode( 'marvelous-wololo-contact-form', 'mwcf_render_shortcode' );
.mwcf_contact_form .mwcf_error {
  padding: 5px 9px;
  border: 1px solid red;
  color: red;
  border-radius: 3px;
}

.mwcf_contact_form .mwcf_success {
  padding: 5px 9px;
  border: 1px solid green;
  color: green;
  border-radius: 3px;
}

.mwcf_contact_form form span.req {
  color: red;
}

.mwcf_contact_form form .hp-field {
  display: none;
}

.mwcf_contact_form form input,
.mwcf_contact_form form textarea {
  display: block;
  margin-bottom: 10px;
}

以上是关于css 逐步返工marvelouswololo的联系表格代码的主要内容,如果未能解决你的问题,请参考以下文章

Java函数的联级调用

FreeSql 导航属性的联级保存功能

特殊状态数据的联表查询统计问题

为什么项目中总是有很多返工?

记一次返工

随一笔:数据库一对多的联表查询