繁体   English   中英

如何在Wordpress中添加自己的联系表格

[英]How can I add my own contact form in wordpress

我在wordpress 3中有一个网站,我想添加新闻简报注册表单,我很困惑,在这里我可以添加php代码以使表单正常工作,请帮助

您可以将其添加到侧栏中的“ dynamic_sidebar”功能之前。

例如:

 HERE YOUR FORM CODE    
<?php /* Widgetized sidebar */
        if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?><?php endif; ?>

检查php标签,确保在嵌入表单代码php时关闭!

我相信您会需要一个插件,以允许Pigi建议在custom_sidebar中使用php代码。 您可以将其添加到sidebar.php文件中,但是在启用了侧边栏的情况下,它会出现在网站的所有区域中。 您可能希望将表单代码保存在单独的文件中,例如:

如果是这样的形式:

<ol class="yourForm">
   <li><label for="contactName">Name</label>
    <input type="text" name="contactName" id="contactName" value="<?php 
      if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="requiredField" />
  <?php if($nameError != '') { ?><span class="error"><?=$nameError;?></span><?php 
  } ?></li>
   <li><label for="email">Email</label>
    <input type="text" name="email" id="email" value="
    <?php if(isset($_POST['email']))  echo $_POST['email'];?>"class="requiredField email" />
    <?php if($emailError != '') { ?>
     <span class="error"><?=$emailError;?></span><?php 
  } ?></li>
   <li class="textarea"><label for="commentsText">Comments</label>
    <textarea name="comments" id="commentsText" rows="20" cols="30" class="requiredField">
    <?php if(isset($_POST['comments'])) { 
     if(function_exists('stripslashes')) { 
      echo stripslashes($_POST['comments']); 
     } else { 
      echo $_POST['comments']; 
     }
     } 
  ?></textarea>
    <?php if($commentError != '') { ?>
     <span class="error"><?=$commentError;?></span><?php 
  } ?></li>
   <li class="inline"><input type="checkbox" name="sendCopy" id="sendCopy" value="true"
    <?php if(isset($_POST['sendCopy']) && $_POST['sendCopy'] == true) 
     echo ' checked="checked"'; ?> />
    <label for="sendCopy">Send a copy of this email to yourself</label></li>
   <li class="screenReader">
    <label for="checking" class="screenReader">If you want to submit this form, do not enter anything in this field</label>
    <input type="text" name="checking" id="checking" class="screenReader" value="
    <?php if(isset($_POST['checking']))  echo $_POST['checking'];?>"/></li>
   <li class="buttons">
    <input type="hidden" name="submitted" id="submitted" value="true" />
    <button type="submit">Email me »</button></li>
</ol>

您将其另存为form.php,并将其上传到主题根目录。

然后,可以通过将以下代码放在sidebar.php文件中,将其添加到所有侧边栏

<div id="myForm"><?php get_template_part('form'); ?></div>

仅在某些页面上使用如下条件语句:

<?php if (is_page_template('index.php')) {
  get_template_part('form');
  } ?>

暂无
暂无

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

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