【问题标题】:Custom form on WordPress blogWordPress 博客上的自定义表单
【发布时间】:2010-11-23 10:10:10
【问题描述】:

我想为我的 WordPress 博客创建一个自定义表单,该表单获取用户的电子邮件地址,然后将其添加到数据库中。我知道如何编写表单和脚本来实现数据存储。不过,我不知道如何将它贴在 WordPress 博客上。

有这种类型的插件,或者有什么方法可以手动将表单添加到页面?

它基本上是一个通知框的注册。

谢谢。

【问题讨论】:

    标签: php forms wordpress


    【解决方案1】:

    如果您的主题已准备好小部件,您可以使用文本小部件添加它

    查看外观>小部件 您可以将 html 添加到文本小部件

    【讨论】:

    • 因为我从 HTML 调用 PHP 脚本来处理表单,它需要在 iFrame 中吗?我在想,如果不是整个博客都会被重定向到处理脚本。
    • 我添加了一个 iframe,然后加载表单。所以重定向不是问题。感谢您的解决方案。
    【解决方案2】:

    如果您使用的不仅仅是 html,您将遇到小部件问题。我建议您自己创建一个小部件。

    这是一个空白插件的代码。在“小部件”功能中添加/调用您的代码。

    <?php
    /*
    Plugin Name: Blank Plugin
    Plugin URI: http://www.example.com/plugins/blankPlugin/
    Description: This is a plugin template
    Author: Your Name
    Version: 0.1
    Author URI: http://www.example.com/about/
    */
    
    class blankPlugin extends WP_Widget {
    
     function blankPlugin() {  // The widget construct. Initiating our plugin data.
      $widgetData = array( 'classname' => 'blankPlugin', 'description' => __( "A blank plugin widget" ) );
      $this->WP_Widget('blankPlugin', __('Blank Plugin'), $widgetData);
     } 
    
     function widget($args, $instance) { // Displays the widget on the screen.
      extract($args);
      echo $before_widget;
      echo $before_title . $instance['title'] . $after_title; 
      echo 'The amount is: '.$instance['amount'];
      echo $after_widget;
     }
    
     function update($new_instance, $old_instance) { // Updates the settings.
      return $new_instance;
     }
    
     function form($instance) { // The admin form. 
      $defaults = array( 'title' => 'Wichita', 'amount' => '45' );
      $instance = wp_parse_args($instance, $defaults); ?>
      <div id="blankPlugin-admin-panel">
       <p>
        <label for="<?php echo $this->get_field_id("title"); ?>">Widget title:</label>
        <input type="text" class="widefat" name="<?php echo $this->get_field_name("title"); ?>" id="<?php echo $this->get_field_id("title"); ?>" value="<?php echo $instance["title"]; ?>" />
       </p>
       <p>
        <label for="<?php echo $this->get_field_id("amount"); ?>">An amount:</label>
        <input type="text" class="widefat" name="<?php echo $this->get_field_name("amount"); ?>" id="<?php echo $this->get_field_id("amount"); ?>" value="<?php echo $instance["amount"]; ?>" />
       </p>
      </div>
    <?php } 
    
    } 
    
    // Register the widget.
    add_action('widgets_init', create_function('', 'return register_widget("blankPlugin");'));
    ?>
    

    有关更多信息...(也请参阅页面底部的链接) http://codex.wordpress.org/Widgets_API#Developing_Widgets

    【讨论】:

      【解决方案3】:

      你可以使用这个wordpress插件http://wordpress.org/extend/plugins/contact-form-7/

      或者可以在你自己的基础上做。

      你可以像这样在你的主题文件夹中创建一个模板:-

      <?php
      /*Template Name: some thing*/
      //your dynamic stuff here
      
      ?>
      

      并且可以将此模板分配给您可以从 wordpress 管理面板创建的静态页面。每当你点击这个静态页面的 paramalink 时,这个文件就会被调用。 因此您可以处理所有邮件内容等。 谢谢。

      【讨论】:

        猜你喜欢
        • 2015-08-28
        • 1970-01-01
        • 1970-01-01
        • 2012-09-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多