简体   繁体   English

WordPress博客上的自定义表格

[英]Custom form on WordPress blog

I would like to create a custom form for my WordPress blog which takes the user's email address and then adds it to a database. 我想为我的WordPress博客创建一个自定义表单,该表单将使用用户的电子邮件地址,然后将其添加到数据库中。 I know how to write the form and script to achieve the data storage. 我知道如何编写表格和脚本来实现数据存储。 I don't know how I would go about sticking it on WordPress blog though. 我不知道如何将其粘贴在WordPress博客上。

Are there any plugins for this type of thing, or is there a way I can manually add the form to the page? 是否有用于此类事情的插件,或者有什么方法可以手动将表单添加到页面?

It's basically a signup for notifications box. 基本上,它是通知框的注册。

Thanks. 谢谢。

You can just add it using the text widget if your theme is widget ready 如果您的主题已准备就绪,则可以使用文本窗口小部件添加它

Look under appearances>widgets You can add html to text widget 在外观下查看>小部件您可以将html添加到文本小部件

If you are using more than html you'll run into problems with the widget. 如果您使用的不是HTML,则小部件会遇到问题。 Upon which I'd recommend that you create a widget yourself. 建议您自己创建一个小部件。

Here is code for a blank plugin. 这是空白插件的代码。 Add/call your code in the "widget" function. 在“窗口小部件”功能中添加/调用您的代码。

<?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");'));
?>

For more information... (see links at the bottom of the page as well) http://codex.wordpress.org/Widgets_API#Developing_Widgets 有关更多信息...(另请参见页面底部的链接) http://codex.wordpress.org/Widgets_API#Developing_Widgets

you can use this wordpress plugin http://wordpress.org/extend/plugins/contact-form-7/ 您可以使用此wordpress插件http://wordpress.org/extend/plugins/contact-form-7/

or can do on your own base. 或者可以根据自己的情况做。

you can create a template inside your theme folder like this:- 您可以在主题文件夹中创建一个模板,如下所示:-

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

?>

and can assign this template to your static page which you can create from the admin panel of wordpress. 并且可以将此模板分配给您的静态页面,您可以从wordpress的管理面板中创建该页面。 whenever you hit the paramalink of this static page this file will be called. 只要您点击此静态页面的超链接,该文件就会被调用。 thus you can handle the everything mail content etc. Thanks. 因此,您可以处理所有邮件内容等。谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM