簡體   English   中英

php處理動態生成的表單

[英]php processing a dynamically generated form

我正在使用php生成一個顯示博客/主題項的html頁面,並且正在使用javascript來顯示/隱藏一些細節。 問題是我為每組隱藏的內容生成了唯一的ID,其中包含用於處理輸入的表單。 在處理表單時,我需要知道編輯了哪個博客項目-我想使用$ _POST。 我對javascript很陌生,並且我認為可能有一種可以在其中使用的解決方案。

我希望該帖子將文本保存到mysql數據庫中(所以調用我正在使用的我的php函數之一),然后告訴我文本是什么以及threadId是什么。

這是php代碼片段,其中$ threadDetailItem是一個數組,其中包含我的線程數據。

   foreach ($threadData as $threadDetailItem)
   {
    // display main line (a bunch of code here ...)


    // append button to edit or delete the post for admin
    if ( isset ($_SESSION['isAdmin']) && $_SESSION['isAdmin'] == 'Y'){
        // edit link opens content, and delete pops up a confirmation box
        $el = sprintf ("editThreadLink_%d", $threadDetailItem['blogThreadId']);
        $ec = sprintf ("editThreadContent_%d", $threadDetailItem['blogThreadId']);
        $link1 = sprintf ("<a id=\"%s\" href=\"javascript:toggle('%s', '%s');\">+</a>", $el, $ec, $el);
        $msg .= sprintf ("<li id=\"field6\">%s</li>\n", $link1);
    } 
    $msg .= "</ul>\n";
    echo $msg;

    // now that the row is printed, lets add the hidden content if admin so they can edit
    if ( isset ($_SESSION['isAdmin']) && $_SESSION['isAdmin'] == 'Y'){
        // hidden content to enable editing of the posting
        $msg = sprintf ("<div id=\"%s\" style=\"display: none\">\n", $ec);
        echo $msg;

        echo "<form name=\"form\" method=\"post\" action=\"\">\n";
        $msg = sprintf ("<textarea id=\"%s\" name=\"%s\">%s</textarea>\n", 
            $ec, $ec, $threadDetailItem['threadTitle']);
        echo $msg;
        $msg = sprintf ("<button type=\"submit\"> %s</button>\n", $lang->get('BLOG POST'));
        echo $msg;
        echo "</form>\n";
        echo "</div>";
    }
}

非常感謝您提出處理此事件的好方法。 提前致謝。

數據中的字段是:blogThreadId,threadTitle,用戶名,createdOn,lastUpdated,顯示(未使用)和threadDetails(包含發布信息的數組)。

我能夠使用$ _POST和隱藏字段中的ID來使我的php腳本知道正在編輯哪個線程。 這是工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM