【问题标题】:Problems storing content from a form via CMS通过 CMS 从表单存储内容的问题
【发布时间】:2011-03-11 06:42:42
【问题描述】:

我有一个名为 sales 的 MySQL 表,包含字段 product、quantity 和 paid。

我正在使用类似 CMS 的系统,该系统具有自定义表单处理方式和自定义表单域。

据我所知,赋予表单域的 id 是用作插入的表名。

我目前使用的表格如下:

<?php

    include("../../include/session.php");
    include("include/tables.php");
    include("include/fields.php");

    //if you need to ovveride the phpbmsTable class make sure to include the modules file
    include("include/sales.php");

    if(!isset($_GET["backurl"]))
        $backurl = NULL;
    else{
        $backurl = $_GET["backurl"];
        if(isset($_GET["refid"]))
            $backurl .= "?refid=".$_GET["refid"];
    }

    $thetable = new sales($db, "tbld:490cf2d1-1c72-7b99-461d-b1b8e68553c4");
    $therecord = $thetable->processAddEditPage();

    if(isset($therecord["phpbmsStatus"]))
        $statusmessage = $therecord["phpbmsStatus"];

    $pageTitle = "Sales";


    $phpbms->cssIncludes[] = "pages/menus.css";
    $phpbms->jsIncludes[] = "modules/base/javascript/menu.js";

        $theform = new phpbmsForm();

        $theinput = new inputSmartSearch($db, "product", "Choose Product",$therecord["product"], "Choose Product", TRUE, NULL, NULL, TRUE, $required=true);
        $theinput->setAttribute("class","important");
        $theform->addField($theinput);

        $theinput = new inputField("quantity",$therecord["quantity"],"Quantity",true, NULL, 1);
        $theinput->setAttribute("class","important");
        $theform->addField($theinput);

        $theinput = new inputCheckbox("paid", $therecord["paid"], "Paid");
        $theform->addField($theinput);

        $thetable->getCustomFieldInfo();
        $theform->prepCustomFields($db, $thetable->customFieldsQueryResult, $therecord);
        $theform->jsMerge();

    include("header.php");

?><div class="bodyline">

    <?php $theform->startForm($pageTitle)?>

    <div id="leftSideDiv">
        <fieldset>
            <legend><label for="S">Sales</label></legend>

            <p class="big"><?php $theform->showField("product"); ?></p>
            <p class="big"><?php $theform->showField("quantity"); ?></p>
            <p class="big"><?php $theform->showField("paid"); ?></p>

        </fieldset>
    </div>
    <?php

        $theform->showGeneralInfo($phpbms,$therecord);
        $theform->endForm();
    ?>
</div>
<?php include("footer.php");?>

数量和已付款的内容可以毫无问题地存储在表格中,但据我所知,产品没有,因为在某些时候 'ds-' 会添加到 id 前面。我想这是因为我使用了不同的输入字段(我需要使用)。

这是尝试保存表单后 POST 的结果:

Array ([product] => 75c72a6a-83d9-11df-951a-fa9c1ec271f2 [ds-product] => Corona [quantity] => 2 [paid] => 0 [createdby] => [creationdate] => [ command] => save [modifiedby] => [cancelclick] => 0 [modifieddate] => [uuid] => :4402add3-b884-43e6-04ad-c76d92ee465b [id] => )

相反,UUID 被插入到产品中,而不是产品名称。

不知道有没有办法解决这个问题?我认为我无法直接更改查询代码,也无法将产品重命名为 ds-product,因为我无法更改查询以访问带连字符的字段名。

有可能覆盖类,如上所述,我已经包含了 sales.php,它基于示例 here

是否以某种方式覆盖 insertRecord 函数的解决方案,如果是,如何?还是有更简单的解决方案?

【问题讨论】:

    标签: php javascript mysql forms post


    【解决方案1】:

    您可以更改数组中项目的值,这样您就可以始终将产品项目覆盖为您想要进入该字段的值。虽然我会说,如果该字段需要一个看起来像的 id 值并且您设置为一个字符串,那么这将不会很好。

    【讨论】:

      猜你喜欢
      • 2013-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多