• csimpson

    (@csimpson)


    Hi there, firstly any help is much appreciated. In very new to php but love wordpress!

    I have searched the web everywhere for a simple solution to my issue but struggled to find a working answer.

    In short, i have a form on homepage that allows entry of arrival date, departure date and number of guests. i need the form to post these parameters to an booking system provided by a third party BUT hosted on my website via an iframe – but another page, not the homepage where the form is – MUST EMPHASIZE THAT).

    Anyway, i’m almost there! but I am struggling to work out the PHP to display a string of php request functions.

    Firstly, my current implementation is showing this code on the page source code (NOTE: iframe delibrately spelt wrong to embed here)

    <iBrame name="testframe" src="https://externalurl?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch&29/11/201330/11/201312"></ibrame>

    The url aspect of the iframe needs to be as follows:

    https://externalurl?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch&arrival=09%2F07%2F2013&departure=10%2F07%2F2013&numberOfPersons=1&numberOfChildren=0

    So I have two problems. I am only showing two dates combined together in my iframe src string, these need to be seperated, and I am also missing two paramters for some uknown reason – number of people parameters.

    Below is my code hardcoded on the iframe php page (html/php) and also my form. Any thoughts, help is much appreciated.

    <ibrame name="testframe" src="https://externalurl?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch<?php echo ''.$_REQUEST['arrival'].$_REQUEST['departure'].$_REQUEST['numberOfPersons'].$_REQUEST['numberOfChildren']?>"></ibrame>

    <form action="/gatehouse-hotel/book-online/" method="get" name="pageform" onsubmit="return validate(this);" target="testframe">
    
    	<div class="FormField Arrival">
    		<label for="arrival">Arrival Date</label> <input id="arrival" name="arrival" type="text" /></div>
    	<div class="FormField Departure">
    		<label for="departure">Departure Date</label> <input id="departure" name="departure" type="text" /></div>
    	<div class="FormField NumberOfPersons">
    		<label for="numberOfPersons">Adults</label> <select id="numberOfPersons" name="numberOfPersons"><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select></div>
    	<div class="FormField NumberOfChildren">
    		<label for="numberOfChildren">Children</label> <select id="numberOfChildren" name="numberOfChildren"><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select></div>
    
    <div class="FormField Submit">
    		<input type="submit" value="Book now" /></div>
              </form>
    
        <script language="JavaScript">
        function validate(theform) {
        if (theform.domain.value == "") { alert("No domain entered"); return false; }
        return true;
        }
        </script>
Viewing 13 replies - 1 through 13 (of 13 total)
  • Moderator bcworkz

    (@bcworkz)

    You are getting the people parameters, the numbers run on into the date so that it is not clear. Consider using the date type input field. It is cool for those browsers that support it. For those that do not it is a normal text field, nothing lost.

    Since people could put anything into a text field, you need to do some validation. One, if they don’t enter anything, you get script errors unless the script is constructed to account for the possibility. array_key_exists() is often used because $_REQUEST will not have the corresponding name key if the field was left blank. Better yet, use javascript to ensure all fields have values. You still need to validate with PHP because not everyone runs javascript.

    Two, you need to format whatever they input into a proper date format expected by the third party iframe source. Use strtotime() to convert any date string into a proper UNIX timestamp. Then use date() to convert the timestamp to the expected date format.

    You need to learn more about constructing strings! ?? You’re just missing certain elements that would result in a correct string. Here is my preferred approach. Others have other ideas. You’ll eventually develop your own. Different quote styles behave differently in PHP. I like to use the double quotes because you can embed variables and they are automatically expanded to their values when you echo out a double quoted string. The only drawback is you need to escape actual double quote characters with either \" or ' – add a backslash or change to single quotes.

    Some people don’t like this style because it can be hard to distinguish the variables from the text. I don’t think so, it’s the words that start with ‘$’. Besides, my text editor knows PHP syntax and colors variables differently than text strings, even inside double quoted strings.

    Anyway, here’s the process. Start with the complete example string with hardcoded example values. You provided:
    https://externalurl?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch&arrival=09/07/2013&departure=10/07/2013&numberOfPersons=1&numberOfChildren=0

    For illustration purposes, lets do the entire “iBrame” string:
    <iBrame name="testframe" src="https://externalurl?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch&arrival=09/07/2013&departure=10/07/2013&numberOfPersons=1&numberOfChildren=0"></iBrame>

    First escape or convert all double quotes (and $ characters):
    <iBrame name=\"testframe\" src=\"https://externalurl?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch&arrival=09/07/2013&departure=10/07/2013&numberOfPersons=1&numberOfChildren=0\"></iBrame>

    Then add all the PHP stuff to echo out the iBrame:
    <?php echo "<iBrame name=\"testframe\" src=\"https://externalurl?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch&arrival=09/07/2013&departure=10/07/2013&numberOfPersons=1&numberOfChildren=0\"></iBrame>"; ?>

    You also need to add code to ensure the date values are the correct format. Lets assume such dates were assigned to $arrival and $departure. You then simply substitute the example values with the actual variables that contain the values. Any complex variable references are enclosed with curly brackets. Use single quotes for array key names.
    <?php echo "<iBrame name=\"testframe\" src=\"https://externalurl?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch&arrival=$arrival&departure=$departure&numberOfPersons=$_REQUEST['numberOfPersons']&numberOfChildren=$_REQUEST['numberOfChildren']\"></iBrame>"; ?>

    That’s it! A fully valid ibrame HTML string is output. You can see that the string is hard to read here even with $ in front of each variable. If you have a syntax highlighting editor, paste the final code into it and see how nicely the variables jump out of the rest of the string.

    Thread Starter csimpson

    (@csimpson)

    Hi bcworkz, thank you very much for your response. so far, i am just receiving a blank screen on the expected iframe page now.

    For my text editor, I use textpad, which does highlight the variables.

    Using your last entry above, replacing iBrame with iframe, and replacing the external url part, it shows the blank page (must be an error somewhere) – also stops showing variables after the first in text editor.

    So, i made all variables use the request function and had to replace & with &amp in between each for the variables to stand out. My last code is below but unfortunately, still shows white screen!

    <?php echo "<iframe name=\"testframe\" src=\"https://uk2.roomlynx.net/rezrooms2/loadOBMApplication.action?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch&arrival=$_REQUEST['arrival']&departure=$_REQUEST['departure']&numberOfPersons=$_REQUEST['numberOfPersons']&numberOfChildren=$_REQUEST['numberOfChildren']\"></iframe>"; ?>

    I have yet to do any validation on the front end, but was at least previously seeing some page. Although did make input field type date and using latest firefox right now.

    Any thoughts?

    Moderator bcworkz

    (@bcworkz)

    Oops, my bad! Sorry about that, the PHP parser cannot figure out where one variable ends and the URL resumes, so all variables need to be enclosed in { curly braces }. It can usually figure things out, I don’t ever remember too well which situations it can’t. This is one of them.

    Thread Starter csimpson

    (@csimpson)

    bcworkz – I cant thank you enough, its working! I’ve used jquery datepicker on front end to valid date the date that is coming though. Only issue is, as you mentioned, when java is turned off. I’ll look into that. Many thanks for your help.

    Thread Starter csimpson

    (@csimpson)

    one small issue going on now! This works in most browsers apart from safari! its changing the date format. As you said i need to format the date format backend in php to ensure the correct format is always used.

    ive looked everywhere and seen so many examples but getting no where whilst changing date formats in outputted string.

    any ideas? I need the dates to be dd/mm/yyyy.

    <?php echo "<iframe name=\"iframeTarget\" id=\"iframeTarget\" src=\"https://uk2.roomlynx.net/rezrooms2/loadOBMApplication.action?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch&arrival={$_REQUEST['arrival']}&departure={$_REQUEST['departure']}&numberOfPersons={$_REQUEST['numberOfPersons']}&numberOfChildren={$_REQUEST['numberOfChildren']}\" frameborder=\"0\" allowTransparency=\"true\" seamless></iframe>"; ?>

    Thread Starter csimpson

    (@csimpson)

    tried this with no success:

    {$_REQUEST = arrival('d/m/Y', strtotime['arrival']}

    Moderator bcworkz

    (@bcworkz)

    Hi csimpson, sorry for the late reply, I’m on the road currently.

    There’s two problems with what you’ve tried. One is you’re a little confused on how data gets passed from one function to another in PHP. I’m not sure how to explain this, maybe you will start to get it in time when you see enough proper examples.

    The other is something you couldn’t have know without more experience. PHP has very limited ability to parse statement inside of the curly brace variable delimiters. This means you need to do your variable assignments before you try to echo a string.

    You should take the date value in $_REQUEST['arrival'] (and similarly for departure), do the conversion, then assign the result to an arbitrary variable to be used in the echo statement. Thus something like this:

    <?php $arrival = date('d/m/Y', strtotime($_REQUEST['arrival']));
    //similar for departure
    //my echo example here with curly braces inserted goes here
    ?>

    Thread Starter csimpson

    (@csimpson)

    yeah kind of get it! although the date coming through now on the source code of the iframe is 01/01/1970! haha.

    <?php $arrivaldate = date('d/m/Y', strtotime($_REQUEST['arrival']));
    //similar for departure
    //my echo example here with curly braces inserted goes here
    ?>
    <?php $departuredate = date('d/m/Y', strtotime($_REQUEST['departure']));
    //similar for departure
    //my echo example here with curly braces inserted goes here
    ?>
    
    <?php echo "<iframe name=\"iframeTarget\" id=\"iframeTarget\" src=\"https://uk2.roomlynx.net/rezrooms2/loadOBMApplication.action?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch&arrival={$arrivaldate}&departure={$departuredate}&numberOfPersons={$_REQUEST['numberOfPersons']}&numberOfChildren={$_REQUEST['numberOfChildren']}\" frameborder=\"0\" allowTransparency=\"true\" seamless></iframe>"; ?>

    OUTCOME from SOURCECODE

    <iframe name="iframeTarget" id="iframeTarget" src="https://uk2.roomlynx.net/rezrooms2/loadOBMApplication.action?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch&arrival=01/01/1970&departure=01/01/1970&numberOfPersons=3&numberOfChildren=4" frameborder="0" allowTransparency="true" seamless></iframe>

    Thread Starter csimpson

    (@csimpson)

    ah ive read around and seeing info that it is detailing this when date is null or not parsed through correctly. still checking

    Thread Starter csimpson

    (@csimpson)

    changing ‘d/m/Y’ to ‘d-m-Y’ does fix the issue in the iframe – i.e. the dates i choose on form are passed through, albeit i need the iframe to actually be 19%2F12%2F2013

    Thread Starter csimpson

    (@csimpson)

    well i’ve made more changes, seems like ive got rid of the 1970 date! but the date still contains ‘/’ and not ‘%2f’ – remember it needs to be like this as its used in my iframe.

    here is what i have now.

    <?php
    $arrivaldate = $_REQUEST['arrival'];
    print date('d/m/Y', $arrivaldate);
    ?>
    <?php
    $departuredate = $_REQUEST['departure'];
    print date('d/m/Y', $departuredate);
    ?>
    <?php echo "<iframe name=\"iframeTarget\" id=\"iframeTarget\" src=\"https://uk2.roomlynx.net/rezrooms2/loadOBMApplication.action?siteId=KAYSCLAY&request_locale=en&chainAction=newAvailabilitySearch&arrival={$arrivaldate}&departure={$departuredate}&numberOfPersons={$_REQUEST['numberOfPersons']}&numberOfChildren={$_REQUEST['numberOfChildren']}\" frameborder=\"0\" allowTransparency=\"true\" seamless></iframe>"; ?>
    Moderator bcworkz

    (@bcworkz)

    Still on the road, as you may have surmised from another late reply. (actually, just got home and trying to get caught up)

    You’ve got the basic idea now, it’s just a matter of formatting the output of date() to meet your needs. One problem remains though, you are printing the date() conversion but you are using the unconverted value in your iframe src string. You need to assign the value returned by date() to the variable you use in the src string. Have you tried something like this:
    $arrivaldate = date('d%2fm%2fY', $arrivaldate);

    If that doesn’t work, you could convert the slash to %2f with urlencode() like so:
    $arrivaldate = urlencode(date('d/m/Y', $arrivaldate));

    Hi, I found this post and it is the closest to what I am looking to do I guess. I have “old school” programming background – Basic, and C, but never made the transition to web based. What I am looking to do seems really simple enough – but I just can’t figure it out… Please help
    I have a website which I am trying to mimic in WordPress. The page in particular is https://www.honoryou.com/memorialgarden.php (I was able to figure the php coding with the help of some other nice folks). Anyway, I have a similar concept already designed in WordPress at https://m.honoryou.com/memorial-garden but I juts can’t figure out how to make the Search button function. It is an IFrame with the src being my php file I created originally. It is set up where I can pass parameters when calling it through the url, but for some reason – either the php isn’t working for me in WordPress or I am just not too familiar at all with how the syntax should be. Please help… the variables for the url would be FName_filter or LName_filter

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Help using PHP Request for posting Form to Iframe’ is closed to new replies.