0

I have a little issue with an imported searchform in wordpress. We have imported the searchform here: http://www.campingsosflores.com/en/ All the code is running inside a wordpress plugin.

searchform

using the following code:

    <?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', // THE ISSUE IS HERE: This value is not added to the link when I click on submit button.

Someone could help me to understand where I'm wrong? Thanks a lot.

1 Answer 1

0

Solved simly adding a js inside the plugin to create the valu age_1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.