views:

32

answers:

1

I have a MySQL table called sales, containing the fields product, quantity and paid.

I am using a CMS like system which has a custom way of doing forms, and custom formfields to use.

As far as I can tell, the id given to a formfield is what is used as the table name to insert into.

My current form I am using is as follows:

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

The contents of quantity and paid get stored in the table without a problem, however product does not, from what I can tell because at some point 'ds-' is prepended to the id. I suppose this is because I am using a different input field(which I need to use).

This is the result of POST after trying to save a form:

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] => )

Instead, the UUID gets inserted into product, instead of the product name.

I wonder if there is any solution to this? I don´t think I have direct access to change the query code, and I can´t rename product to ds-product because I can´t change the query to access a hyphenated fieldname.

There is the possibility to override classes, as above I have inlcluded sales.php, which is based on the sample here.

Is the solution to somehow override the insertRecord function, and if so how? Or is there a simpler solution?

A: 

You can change the values of the items in the array so you could always overwrite the product item to be the value you want to go into the field. Though I would say that if the field is expecting a id value as it seems and you set to a string then this will not work very well.

spinon