我对wordpress中导入的searchform有点问题。我们已在此处导入searchform:http://www.campingsosflores.com/en/所有代码都在wordpress插件中运行。
使用以下代码:
<?php
function netbooking_searchform($content){
$GLOBALS["content"] = $content;
// Function to read a default value in case of error
$INPUT = function($param, $default = "", $prefix = true){
$key = $prefix ? \'netbooking_searchbox_\'.$param : $param;
return isset($GLOBALS["content"][$key]) ? $GLOBALS["content"][$key] : $default;
};
$language = $INPUT(\'language\', \'it\', false);
$lang = substr($language, 0, 2);
$cryptedID = $INPUT(\'crypted_id\', \'OiAmpE15aWU=\', false);
$mod = $INPUT(\'mod\', \'v\', false);
// Search form sections to be shown
$displayOptions = array();
$displayOptions[\'show_arrival_date\'] = "#datefromlabel {display:none;} #datefromvalue {display:none;}";
$displayOptions[\'show_departure_date\'] = "#datetolabel {display:none;} #datetovalue {display:none;}";
$displayOptions[\'show_number_of_persons\'] = "#numpeoplelabel {display:none;} #numpeoplevalue {display:none;}";
$displayOptions[\'show_type\'] = "#structuresnameslabel {display:none;} #structuresnamesvalue {display:none;}";
// Create CSS using parameters from the form
$css = "";
foreach ($displayOptions as $key => $option) {
$toShow = $INPUT($key, "on");
if (isset($toShow) && $toShow != "on"){
$css .= $option;
}
}
$customlabel = \'Bambini (4 - 10 anni)\';
if ($lang == \'en\') $customlabel = "Children (4 - 10 Years)"; // Language String for label
// Get searchform HTML from WebService
$api = \'https://webserverlink.com/p/\'.$cryptedID.\'/it/index.php\';
$query = http_build_query([
\'type\' => \'p\',
\'returnmod\' => \'xml\',
\'id\' => $cryptedID,
\'cmd\' => \'searchform\',
\'l\' => substr($language, 0, 2),
\'mask\' => \'1111110\',
\'mod\' => $mod,
\'lblchildren\'=> $customlabel,
**\'age_1\' => \'4\',** // THE ISSUE IS HERE: This is not added to the link when I click on submit button
\'nocss\' => \'0\'
]);
$searchform_html = file_get_contents($api. \'?\' . $query );
$searchform_html = utf8_decode($searchform_html);
// DOM Parsing
libxml_use_internal_errors(true);
$dom = new DOMDocument;
$dom->loadHTML($searchform_html);
$xpath = new DOMXPath($dom);
$booking = $dom->getElementById(\'booking\');
//$booking->removeChild($booking->firstChild); // ... #booking has a first child we don\'t know about...
// Utility Fuction
$appendAttribute = function($dom, $element, $attribute_name, $value){
$attribute = $dom->createAttribute($attribute_name);
$attribute->value = $value;
$element->appendChild($attribute);
};
$createStyleElement = function($dom, $css_str) {
$appendAttribute = function($dom, $element, $attribute_name, $value){
$attribute = $dom->createAttribute($attribute_name);
$attribute->value = $value;
$element->appendChild($attribute);
};
$style_node = $dom->createElement(\'style\', $css_str);
$appendAttribute($dom, $style_node, \'type\', \'text/css\');
return $style_node;
};
$createLinkElement = function($dom, $url) {
$appendAttribute = function($dom, $element, $attribute_name, $value){
$attribute = $dom->createAttribute($attribute_name);
$attribute->value = $value;
$element->appendChild($attribute);
};
$link_node = $dom->createElement(\'link\');
$appendAttribute($dom, $link_node, \'rel\', \'stylesheet\');
$appendAttribute($dom, $link_node, \'type\', \'text/css\');
$appendAttribute($dom, $link_node, \'href\', $url);
return $link_node;
};
// New styles to add
//$defaultStyle = $createStyleElement($dom, $cssOptions[\'default\']);
$cssCleanerStyle = $createLinkElement($dom, "http://yui.yahooapis.com/3.18.1/build/cssreset-context/cssreset-context-min.css");
$customStyle = $createStyleElement($dom, $css);
$googleFontsLink = $createLinkElement($dom, "https://fonts.googleapis.com/css?family=Alegreya|Alegreya Sans|Anonymous Pro|Archivo Narrow|Arvo|BioRhyme|Bitter|Cabin|Cardo|Chivo|Cormorant Garamond|Crimson Text|Domine|Eczar|Fira Sans|Gentium Basic|Inconsolata|Karla|Lato|Libre Baskerville|Libre Franklin|Lora|Merriweather|Montserrat|Neuton|Old Standard TT|Open Sans|PT Sans|PT Serif|Playfair Display|Poppins|Rajdhani|Raleway|Roboto|Roboto Slab|Rubik|Source Sans Pro|Source Serif Pro|Space Mono|Work Sans");
$netbookingStyle = $booking->firstChild;
$booking->removeChild($booking->firstChild); // remove to add later
// styles added from last to first (cause only "insertBefore" exist here...)
$toInsert = [$googleFontsLink, $customStyle, $netbookingStyle, /*$defaultStyle, */$cssCleanerStyle];
foreach ($toInsert as $element) {
$booking->insertBefore($element, $booking->firstChild);
}
?>
<div class="yui3-cssreset mod<?= $mod;?>">
<?= $dom->saveHTML();?>
</div>
<?php };
?>
\'age_1\' => \'4\', // 问题就在这里:当我点击提交按钮时,这个值并没有添加到链接中。
有人能帮我理解我错在哪里?非常感谢。