dongyan1993 2010-07-02 06:51
浏览 72
已采纳

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

I am working within the confines of a php based CMS like system, which defines custom form fields that can be used when making a new page.

I have two tables in my database, one called people, which has three fields, firstname, middlename and lastname, and a second table called orders, which also has firstname, middlename and lastname fields, as well as product, quantity and cost.

I am using one of the custom fields, inputSmartSearch, which works somewhat like google suggest. As I type letters an SQl query is performed returning results that match, concatenated together.

For example, if I put 'ba' as the input, one result might be 'banner, david, bruce', and after I select it 'banner, david, bruce' is now the text content in the inputSmartSearch field.

in the people table, david is in the firstname field, bruce in the middlename field and banner in the lastname field.

What I want to do is find out how to access the text that is present in the inputsmartsearch field(i.e. whatever the user has selected), and break it again up to 3 parts, so I can insert the firstname into orders.firstname, middlename into orders.middlename and lastname into orders.lastname, as well as the input from the other simpler fields on the site into their relevant fields in the orders table.

There may well be a simpler solution, such as using a unique primary guestid and just inserting that into the orders table, but even then my current problem is still the same.

How do I access the content of the inputsmartsearch field after it is full?

The HTML generated by a search is as follows:

<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>

Since that generated HTML is dynamic, I don´t know how much use it will be.

The generated HTML for the actual field never changes, even when filled with a value...so I don´t know how to access what it holds.

It is as follows:

    <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>

I am limited in what javascript I can use(I think), and must use fields defined by the CMS system(I think...but not sure....perhaps no requirement to do so...)

Some pointers in the general direction here would be amazing.

edit:

This is the _POST data that gets sent:

Array ( [chooseguests] => :08490ea8-d654-1c91-cb82-00d44a4b093b [ds-chooseguests] => Holmes, Sherlock [chooseproducts] => 75c72a6a-83d9-11df-951a-fa9c1ec271f2 [ds-chooseproducts] => Corona [quantity] => 2 [type] => cash [receiptno] => 7 [createdby] => [creationdate] => [command] => save [modifiedby] => [cancelclick] => 0 [modifieddate] => [uuid] => :4402add3-b884-43e6-04ad-c76d92ee465b [id] => )

And this is my current form, based on the template linked above:

<?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");?>

I have trimmed it as much as I can, and only left in those comments that I think may be useful for relating to the problem/question.

  • 写回答

1条回答 默认 最新

  • doudun3040 2010-07-02 07:03
    关注

    So without seeing all the working code and knowing what limits you have I would approach it with something like this. It looks like you can get the contents of the selection by just reading the value from the input text field.

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

    I would imagine that this has the contents of the selection.

    Then you can just do a split on the value:

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

    Now you can access each part with an index

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

    I tried to keep it using basic javascript with no external libraries. Hopefully this is what you had in mind.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘