Я работаю в рамках CMS-подобной системы на основе php, которая определяет настраиваемые поля формы, которые можно использовать при создании новой страницы.
В моей базе данных есть две таблицы, одна из которых называется people,в котором есть три поля: имя, отчество и фамилия, а также вторая таблица, называемая заказами, в которой также есть поля имя, отчество и фамилия, а также продукт, количество и стоимость.
Я использую одно из пользовательскихполя, inputSmartSearch, который работает примерно так, как предлагает Google.Когда я набираю буквы, выполняется SQl-запрос, возвращающий совпадающие результаты, объединенные вместе.
Например, если в качестве входных данных указать «ba», одним из результатов может быть «banner, david, bruce», а послеЯ выбрал его: «banner, david, bruce» теперь является текстовым содержимым в поле inputSmartSearch.
в таблице сотрудников, david находится в поле имени, bruce в поле среднего имени и баннер в поле фамилии.
Что я хочу сделать, так это выяснить, как получить доступ к тексту, присутствующему в поле inputmartsearch (т.е. независимо от того, что выбрал пользователь), и разбить его снова на 3 части, чтобы я мог вставить имяв orders.firstname, middlename into orders.middlename и lastname into orders.lastname, а также входные данные из других более простых полей сайта в соответствующие поля таблицы заказов.
Вполне возможно, чтоболее простое решение, такое как использование уникального первичного гестида и просто вставка его в таблицу заказов, но даже тогда мой текущий pпроблема все та же.
Как получить доступ к содержимому поля 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 (я думаю ... но не уверен ... возможно, нет необходимости делать это ...)
Некоторые указатели в общем направлении здесь были бы удивительными.
edit:
Это _POST-данные, которые отправляются:
Array ([chooseghest] =>: 08490ea8-d654-1c91-cb82-00d44a4b093b [ds-chooseghest] => Холмс, Шерлок [выбрать продукты] => 75c72a6a-83d9-11df-951a-fa9c1ec271f2 [ds-chooseproducts] => Corona [количество] => 2 [тип] => наличные [реceiptno] => 7 [createby] => [creationdate] => [команда] => сохранить [updatedby] => [cancelclick] => 0 [updateddate] => [uuid] =>: 4402add3-b884-43e6-04ad-c76d92ee465b [id] =>)
И это моя текущая форма, основанная на шаблоне, указанном выше:
<?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");?>
Я обрезал ее столько, сколько смог, и оставил тольков тех комментариях, которые я считаю полезными для связи с проблемой / вопросом.