将动态文本字段的结果存储到单独的数据库字段中

时间:2010-07-02 06:51:33

标签: php javascript sql mysql ajax

我在基于php的CMS系统的范围内工作,该系统定义了在制作新页面时可以使用的自定义表单字段。

我的数据库中有两个表,一个名为people,有三个字段,firstname,middlename和lastname,第二个表名为orders,它们还有firstname,middlename和lastname字段,以及产品,数量和成本。

我正在使用其中一个自定义字段inputSmartSearch,其工作方式有点像google建议。当我输入字母时,执行SQl查询返回匹配的结果,连接在一起。

例如,如果我将'ba'作为输入,一个结果可能是'banner,david,bruce',在我选择它'banner,david,bruce'之后现在是inputSmartSearch字段中的文本内容。

人员表中的

,david位于firstname字段中,bruce位于middlename字段中,banner位于lastname字段中。

我想要做的是找出如何访问输入智能搜索字段中存在的文本(即用户选择的任何内容),并再次将其分解为3个部分,这样我就可以将第一个名称插入到订单中。 firstname,middlename into orders.middlename和lastname into orders.lastname,以及从网站上其他更简单的字段输入到orders表中的相关字段。

可能有一个更简单的解决方案,例如使用唯一的主要猜测并将其插入到订单表中,但即便如此,我当前的问题仍然是相同的。

如何在inputmartsearch字段填满后访问该内容?

搜索生成的HTML如下:

<div id="searchBox-chooseguests" class="smartSearchBox" style="top: 199px; left: 42px; width: 190px;">
<div id="SBHeader-chooseguests" class="SBHeader">
<button tabindex="4000" class="graphicButtons buttonX" id="SBCloseButton-chooseguests" type="button">
<span>close</span>
</button></div>
<div id="SBResults-chooseguests" class="SBResults"> 
<a tabindex="4000" id="SB-:08490ea8-d654-1c91-cb82-00d44a4b093b" class="SBSearchItems SBSI-chooseguests " href="#">
<span class="SBMain">Sherlock Homes</span>
<span class="SBExtra">333333334</span>
</a>
</div>
<div id="SBFooter">
</div>
</div>

由于生成的HTML是动态的,我不知道它会有多大用处。

生成的实际字段的HTML永远不会更改,即使填充了值...所以我不知道如何访问它所拥有的内容。

如下:

    <p class="big"><label for="ds-chooseguests">Choose Guest</label>
<br>
<input type="hidden" value=":08490ea8-d654-1c91-cb82-00d44a4b093b" id="chooseguests" name="chooseguests">
            <input type="hidden" value="1" id="sff-chooseguests">
            <input type="hidden" value="17" id="sdbid-chooseguests">
            <input type="text" value="" class="inputSmartSearch important" title="Use % for wildcard searches." id="ds-chooseguests" name="ds-chooseguests" autocomplete="off"></p>

我受限于我可以使用的javascript(我认为),并且必须使用CMS系统定义的字段(我认为......但不确定......也许没有要求这样做......)< / p>

这里总体方向的一些指示将是惊人的。

编辑:

这是发送的_POST数据:

数组([chooseguests] =&gt;:08490ea8-d654-1c91-cb82-00d44a4b093b [ds-chooseguests] =&gt; Holmes,Sherlock [chooseproducts] =&gt; 75c72a6a-83d9-11df-951a-fa9c1ec271f2 [ds-选择产品] =&gt;电晕[数量] =&gt; 2 [类型] =&gt;现金[receiptno] =&gt; 7 [createdby] =&gt; [creationdate] =&gt; [command] =&gt;保存[modifiedby] = &gt; [cancelclick] =&gt; 0 [modifieddate] =&gt; [uuid] =&gt;:4402add3-b884-43e6-04ad-c76d92ee465b [id] =&gt;)

这是我目前的表格,基于上面链接的模板:

<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

    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 the addedit page will be accessd directly from a page other than the
    // basic search results page, you may want to grab and pass the previous URL
    //with the following code

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

    //      $thetable = new phpbmsTable($db,[table definition id]);
    // Next we process the form (if submitted) and
    // return the current record as an array ($therecord)
    // or if this is a new record, it returns the defaults
    $thetable = new sales($db, "tbld:490cf2d1-1c72-7b99-461d-b1b8e68553c4");
    $therecord = $thetable->processAddEditPage();

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

    $pageTitle = "Sales";

    // Next, we set up to include any
    // additional css or javascript files we will be using
    //  This does nto include any field-type specific js (like datepicker)
    // as they are automatically icluded when you define the special fields you
    // will be using below.
    $phpbms->cssIncludes[] = "pages/menus.css";
    $phpbms->jsIncludes[] = "modules/base/javascript/menu.js";
    $phpbms->jsIncludes[] = "modules/micro hospitality/javascript/checkpaid.js";

    // DEPRECIATED:
    // if you need to define a body onlload function, do so with the phpbms property
    $phpbms->onload[] = "initializePage()";

print_r($_POST);
    // Next we need to define any special fields that will be used in the form
    // A list of field objects (with documentation)is available in the /include/fields.php
    // file.

    // We need to define them here in the head
    // so that any necessay javascript is loaded appropriately.

        $theform = new phpbmsForm();
        //if you need to set specific form vaiables (like enctype, or extra onsubmit
        // you can set those form properties here.

        // for each field we will use, create the field object and add it to
        // the forms list.

        $theinput = new inputSmartSearch($db, "chooseguests", "Choose Guests",NULL, "Choose Guest", TRUE, NULL, NULL, TRUE, $required=true);
        $theinput->setAttribute("class","important");
        $theform->addField($theinput);

        $theinput = new inputSmartSearch($db, "chooseproducts", "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 inputBasicList("type",$therecord["paymenttype"],array("Cash"=>"cash","Credit"=>"credit"), "Payment Type");
        $theinput->setAttribute("class","important");
        $theform->addField($theinput);

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

        $theinput = new inputField("receiptno",$therecord["receiptno"],"Receipt No",true, NULL, 10);
        $theinput->setAttribute("class","important");
        $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("chooseguests"); ?></p>
            <p class="big"><?php $theform->showField("chooseproducts"); ?></p>
            <p class="big"><?php $theform->showField("quantity"); ?></p>
            <p class="big"><?php $theform->showField("type"); ?></p>
            <p class="big"><?php $theform->showField("paid"); ?></p>
            <p class="big"><?php $theform->showField("receiptno"); ?></p>


        </fieldset>
    </div>
    <?php
        //Last, we show the create/modifiy with the bottom save and cancel buttons
        // and then close the form.
        $theform->showGeneralInfo($phpbms,$therecord);
        $theform->endForm();
    ?>
</div>
<?php include("footer.php");?>

我尽可能地修剪它,并且只留下那些我认为可能对问题/问题有用的评论。

1 个答案:

答案 0 :(得分:0)

因此,如果没有看到所有正常工作的代码并知道你有什么限制,我会用这样的方法来处理它。看起来您只需从输入文本字段中读取值即可获取选择内容。

var selection = document.getElementById("ds-chooseguests").value

我想这会有选择的内容。

然后你可以对值进行拆分:

var selection_parts = selection.split(',');

现在您可以使用索引访问每个部分

selectionParts[0] = "banner ";
selectionParts[1] = "david ";
selectionParts[2] = "bruce ";

我尝试使用没有外部库的基本javascript来保持它。希望这是你的想法。

相关问题