Wordpress管理页面剥离表单标签

时间:2013-04-25 18:41:34

标签: php html wordpress forms wordpress-plugin

我有一个我在wordpress中编写的php页面,该页面应该从数据库中获取一些信息并将其显示在页面中。我正在尝试添加直接从页面更新信息的能力,似乎正在剥离我的第一个表单标签,而不是其他的。有没有人见过这样的事情或者可能知道可能发生的事情?

这是PHP

function display_terms_by_brand()
{
global $wpdb;
$sql = "SELECT * FROM ".NINJA_FORMS_TERMS_TEXT;
$terms = $wpdb->get_results($sql, ARRAY_A);
?>

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('.edit').click(function(){
            jQuery(this).parent().find('.edit').css('display' , 'none')
            jQuery(this).parent().find('.save').css('display' , 'block')
            jQuery(this).parent().siblings('span[id*=brand_text_]').children('span').toggle();
            jQuery(this).parent().siblings('span[id*=brand_text_]').children('textarea').toggle();
        }); 
    })
</script>

<div id="termsHeader" style="font-weight:bold; font-size:16px; padding:10px 0; height:30px; min-width:600px;">
    <span style="width:10%; text-align:center; float:left; padding:0 30px;">Brand</span>
    <span style="width:67%; text-align:center; float:left;">Text</span>
    <span style="width:9%; text-align:center; float:right; padding:0 15px;">Edit / Save</span>
</div>

<div style="clear:both;"><!-- --></div>
<hr />

<?php
foreach($terms as $curr_term) {
?>

    <div style="width:100%; padding:20px 0; min-width:600px;" class="term">
        <span style="width:10%; height:50px; padding:30px; float:left; text-align:center;" id="brand_name_<?php echo $curr_term['text_id'] ?>">
            <?php echo $curr_term['brand_name'] ?>
        </span>
        <span style="width:67%; height:50px; padding:30px 10px; float:left;" id="brand_text_<?php echo $curr_term['text_id'] ?>">
            <span> <?php echo stripslashes($curr_term['brand_text']) ?> </span>
            <textarea style="display:none; width:100%;"><?php echo stripslashes($curr_term['brand_text']) ?></textarea>
        </span>
        <span style="width:12%; height:50px; padding:30px 10px; float:right;">
            <form action="/wp-admin/admin.php?page=ninja-forms-extend" method="post" name="edit_<?php echo $curr_term['text_id'] ?>" id="edit_<?php echo $curr_term['text_id'] ?>">
                <input name="brand_name" type="hidden" value="<?php echo $curr_term['brand_name'] ?>" />
                <textarea name="brand_text" style="display:none;">TEST</textarea>
                <input class="termsEditButton termsButtons edit" style="width:150px; margin:0 auto; display:block;" name="edit" type="button" value="Edit Optin Statement" />  
                <input class="termsSaveButton termsButtons save" style="width:150px; margin:0 auto; display:none;" name="save" type="button" value="Save Optin Statement" />  
                <input class="termsDeleteButton termsButtons delete" style="width:150px; margin:0 auto; display:block;" name="delete" type="button" value="Delete Optin Statement" />  
            </form>
        </span>
    </div>

    <div style="clear:both;"><!-- --></div>
<?php
}
?>


<hr />
<h2>Add New Terms text</h2>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>?page=ninja-forms-extend" method="post" name="add_new_term_text" id="add_new_term_text">
    <label style="float:left;width:50px;clear:left;font-weight:bold">Brand</label><input name="brand_name" type="text" size="38" />&nbsp;&nbsp;(This will be the shortcode to display the text)<br />
    <label style="float:left;width:50px;clear:left;font-weight:bold">Text</label><textarea name="brand_text" cols="35" rows="5"></textarea><br />
    <input name="submit" type="submit" value="Add New Terms Text" />
</form>
<?php
return;
}

并且第一次通过循环得到的html是这样的:

<div style="width:100%; padding:20px 0; min-width:600px;" class="term">
        <span style="width:10%; height:50px; padding:30px; float:left; text-align:center;" id="brand_name_1">
            caprizehouse            </span>
        <span style="width:67%; height:50px; padding:30px 10px; float:left;" id="brand_text_1">
            <span> I certify that I am a resident of Canada over the age of 18, I agree to the <a href="http://coreg.intela.com/media/ca-prizehouse/privacypolicy.htm" class="fancylink" target="_blank">Privacy Policy</a> and <a href="http://coreg.intela.com/media/ca-prizehouse/terms.htm" class="fancylink" target="_blank">Terms and Conditions</a>, and I would like to receive the Canadian Prize House newsletter. </span>
            <textarea style="display:none; width:100%;">I certify that I am a resident of Canada over the age of 18, I agree to the &lt;a href="http://coreg.intela.com/media/ca-prizehouse/privacypolicy.htm" class="fancylink" target="_blank"&gt;Privacy Policy&lt;/a&gt; and &lt;a href="http://coreg.intela.com/media/ca-prizehouse/terms.htm" class="fancylink" target = "_blank"&gt;Terms and Conditions&lt;/a&gt;, and I would like to receive the Canadian Prize House newsletter.</textarea>
        </span>
        <span style="width:12%; height:50px; padding:30px 10px; float:right;">

                <input name="brand_name" type="hidden" value="caprizehouse">
                <textarea name="brand_text" style="display:none;">TEST</textarea>
                <input class="termsEditButton termsButtons edit" style="width:150px; margin:0 auto; display:block;" name="edit" type="button" value="Edit Optin Statement">  
                <input class="termsSaveButton termsButtons save" style="width:150px; margin:0 auto; display:none;" name="save" type="button" value="Save Optin Statement">  
                <input class="termsDeleteButton termsButtons delete" style="width:150px; margin:0 auto; display:block;" name="delete" type="button" value="Delete Optin Statement">  

        </span>
    </div>

注意缺少表单标记。从另外两个循环遍历循环,这是页面的HTML输出:

<div style="width:100%; padding:20px 0; min-width:600px;" class="term">
        <span style="width:10%; height:50px; padding:30px; float:left; text-align:center;" id="brand_name_2">
            canadianprizes          </span>
        <span style="width:67%; height:50px; padding:30px 10px; float:left;" id="brand_text_2">
            <span> I certify that I am a Canadian resident above the age of 18 years and I agree to and accept the  <a target="_blank" class="fancylink" href="http://www.canadianprizes.com/media/canadianprizes/terms.jspx"> Terms and Conditions</a>, <a target="_blank" class="fancylink" href="http://www.canadianprizes.com/media/canadianprizes/privacy.jspx">Privacy Policy</a> and <a target="_blank" class="fancylink" href="http://www.canadianprizes.com/media/canadianprizes/prizepolicy.jspx">Competition Rules</a>. I consent to my personal details being provided to  selected clients, sponsors and affiliates and to being contacted via email, phone, SMS or mail, as described in the Privacy Policy. </span>
            <textarea style="display:none; width:100%;">I certify that I am a Canadian resident above the age of 18 years and I agree to and accept the  &lt;a target="_blank" class="fancylink" href="http://www.canadianprizes.com/media/canadianprizes/terms.jspx"&gt; Terms and Conditions&lt;/a&gt;, &lt;a target="_blank" class="fancylink" href="http://www.canadianprizes.com/media/canadianprizes/privacy.jspx"&gt;Privacy Policy&lt;/a&gt; and &lt;a target="_blank" class="fancylink" href="http://www.canadianprizes.com/media/canadianprizes/prizepolicy.jspx"&gt;Competition Rules&lt;/a&gt;. I consent to my personal details being provided to  selected clients, sponsors and affiliates and to being contacted via email, phone, SMS or mail, as described in the Privacy Policy.</textarea>
        </span>
        <span style="width:12%; height:50px; padding:30px 10px; float:right;">
            <form action="/wp-admin/admin.php?page=ninja-forms-extend" method="post" name="edit_2" id="edit_2">
                <input name="brand_name" type="hidden" value="canadianprizes">
                <textarea name="brand_text" style="display:none;">TEST</textarea>
                <input class="termsEditButton termsButtons edit" style="width:150px; margin:0 auto; display:block;" name="edit" type="button" value="Edit Optin Statement">  
                <input class="termsSaveButton termsButtons save" style="width:150px; margin:0 auto; display:none;" name="save" type="button" value="Save Optin Statement">  
                <input class="termsDeleteButton termsButtons delete" style="width:150px; margin:0 auto; display:block;" name="delete" type="button" value="Delete Optin Statement">  
            </form>
        </span>
    </div>

您会注意到表格标签已正确应用。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。事实证明,我完全忽略了这样一个事实,即我在主要选项中填写了表格。