www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28

Thread: Passing URL variable to iframe in another page

  1. #16
    Join Date
    Jun 2012
    Posts
    17
    PHP is supported by my host and by my version of IIS too (I installed the PHP support package onto my IIS system for testing my site).
    The problem is that my layout is generated by a website builder which generates everything in HTML. Is there some way I could get the PHP to parse correctly within an HTML page or is that a no-hoper?

  2. #17
    Join Date
    Jan 2009
    Posts
    3,346
    Quote Originally Posted by PotterNet View Post
    PHP is supported by my host and by my version of IIS too (I installed the PHP support package onto my IIS system for testing my site).
    The problem is that my layout is generated by a website builder which generates everything in HTML. Is there some way I could get the PHP to parse correctly within an HTML page or is that a no-hoper?
    You can get php to parse html files (this can cause some performance issues if you have lots of html files that do not contain php codes). A better solution is to rename the files so they have a .php extension.

  3. #18
    Join Date
    Jun 2012
    Posts
    17
    As in index.html to index.php, servers.html to servers.php etc? Wouldn't that cause issues with html code being loaded in browsers or would all the html load OK?

    Do I just rename the files or do I need to add anything into them for this to work?

  4. #19
    Join Date
    Jan 2009
    Posts
    3,346
    Quote Originally Posted by PotterNet View Post
    As in index.html to index.php, servers.html to servers.php etc? Wouldn't that cause issues with html code being loaded in browsers or would all the html load OK?

    Do I just rename the files or do I need to add anything into them for this to work?
    Just renaming the files will do just fine. The browser doesn't make a distinction between any extensions (or no extensions). It handles the results based on the mime type (in most cases it is text/html).

  5. #20
    Join Date
    Jun 2012
    Posts
    17
    One I rename the files to PHP, how exactly would the code work to get teh variable to pass over?
    I guess it would be
    Code:
    <iframe src=http://external.url/order.php?form=$plan></iframe>
    and I could put the $plan=$_GET['plan'] somewhere nearer the top of the code to get it working?

    Or would I need to edit the lines of code to get it working?

    Or could I safely combine the two lines into the iframe src to get it working?

    If the answer is yes to any of the above, which would be best? Sorry if I seem repetative but my PHP knowledge is non-existant at present (I am looking into learning it but my brain is finding it hard to understand, lol).

  6. #21
    Join Date
    Mar 2012
    Posts
    1,122
    Quote Originally Posted by PotterNet View Post
    Firstly: My pages are ALL .HTML documents.
    And they still will be. They just need to be CALLED .PHP so the server knows there is embeded PHP code in the HTML file.

    Quote Originally Posted by PotterNet View Post
    Secondly: I tried your approach using
    Code:
    <iframe src=http://external.url/order?plan=<? php echo $plan; ?>></iframe>
    and it didn't seem to work, despite there being a <?php $plan=$_GET['plan'] ?> in place at the start of the page's coding too. I also tried it as
    Code:
     <iframe src=http://external.url/order?plan=<?php $plan=$_GET['plan'];
    echo $plan;
    ?>
    too but this didn't seem to work either. Where am I going wrong?
    That is only a generic example of the syntax. It's not intended to be the precise wording you need, because I do not know the wording you need. What you need to do is to take a call to a specific form that actually works, and substitute <?php echo $plan; ?> for the literal plan number e.g. 44944. That should make it work for any plan number, so long as $plan is set to the required plan number.

    Quote Originally Posted by PotterNet View Post
    Please note, the "plan=" is actually a querystring of the iframe src, not a part of the file name. (ie http://external.url/order.php?plan=44944, not http://external.url/order/plan44944.php)
    OK.

    Quote Originally Posted by PotterNet View Post
    And please note, the reason for using external url for the form is because I am a reseller and the form is on the wholesale supplier's site.
    That makes sense. Thanks for clarifying.

  7. #22
    Join Date
    Jun 2012
    Posts
    17
    but $_GET['plan'] would grab the number from the "plan=" part of the link that lead to the page I guess?

  8. #23
    Join Date
    Jun 2012
    Posts
    17
    What I am after clarifying then is the following:
    Should I rename my "my-page.html" to "my-page.php" and have the iframe src written as
    Code:
     <iframe src="http://external.url/order.php?plan=<?php $plan=$_GET['plan'];
    echo $plan;
    ?>"></iframe>
    Would this work or would I need more in the coding of the file to get this to work?
    Last edited by PotterNet; 06-18-2012 at 03:59 PM.

  9. #24
    Join Date
    Jan 2009
    Posts
    3,346
    You should be checking to make sure the value is numeric and what you are expecting.

    PHP Code:
    <?php
    if(!isset($_GET['plan']) || !is_numeric($_GET['plan'])){ //checks that a plan was sent and is a number
    die("Invalid plan number"); //stops processing the script and spits out a message
    } else {
    ?>
     <iframe src="http://external.url/order.php?plan=<?php echo $_GET['plan'];
    ?>"></iframe>

    <?php
    // closes the else statement, anything you want to show after the iframe even if the plan number isn't correct should go after this bracket
    ?>

  10. #25
    Join Date
    Mar 2012
    Posts
    1,122
    Quote Originally Posted by PotterNet View Post
    One I rename the files to PHP, how exactly would the code work to get teh variable to pass over?

    I guess it would be
    Code:
    <iframe src=http://external.url/order.php?form=$plan></iframe>
    and I could put the $plan=$_GET['plan'] somewhere nearer the top of the code to get it working?
    Not quite. Assuming that :

    Code:
    <iframe src=http://external.url/order.php?form=44944></iframe>
    successfully displays form 44944, it should be amended to:

    Code:
    <iframe src=http://external.url/order.php?form=<?php echo $plan; ?>></iframe>

    Quote Originally Posted by PotterNet View Post
    Or could I safely combine the two lines into the iframe src to get it working?

    If the answer is yes to any of the above, which would be best? Sorry if I seem repetative but my PHP knowledge is non-existant at present (I am looking into learning it but my brain is finding it hard to understand, lol).
    It would be better to keep them separate, because that would facilitate adding error handling, if required, at a future date.

  11. #26
    Join Date
    Mar 2012
    Posts
    1,122
    Quote Originally Posted by PotterNet View Post
    What I am after clarifying then is the following:

    Should I rename my "my-page.html" to "my-page.php"
    Yes.

    Quote Originally Posted by PotterNet View Post
    and have the iframe src written as
    Code:
     <iframe src="http://external.url/order.php?plan=<?php $plan=$_GET['plan']; echo $plan;?>"></iframe>
    Would this work or would I need more in the coding of the file to get this to work?
    This should work, but is unnecessary. If you are not going to put $plan=$_GET{'plan'] separate (to allow error checking to be added later) you may as well put:

    Code:
     <iframe src="http://external.url/order.php?plan=<?php echo $_GET['plan'];?>"></iframe>
    Oh, and a small point. You might consider adding an error message for the minority of devices that do not support Iframes. This is simple to do. Just put something like:

    Code:
     <iframe src="http://external.url/order.php?plan=<?php echo $plan;?>">Sorry, your browser does not support this facility. Please contact <whoever>... </iframe>
    Last edited by jedaisoul; 06-18-2012 at 04:45 PM.

  12. #27
    Join Date
    Jan 2014
    Location
    Calgary, Canada
    Posts
    30
    script language="javascript" type="text/javascript">
    google.load('visualization', '1', {packages:['gauge']});
    function Split_Instant(Rec_String)
    {
    //Voltage Local Variable
    solarvoltage=0;

    //var cp1=0;
    //Power Local Variable
    // var pch1=0;
    //var pch2=0;
    //var pp1=0;

    var currentmax=100;

    var parametervalue;
    //alert(Rec_String);
    if(Rec_String!='')
    {
    //alert(Rec_String);
    //Draw_Gauge_Chart(0,0,0,0,0,0,0,0,0,0,0);
    var parametervalue = Rec_String.split("!");
    //alert(parametervalue[3]);
    //3Phase Meter No
    solarvoltage=parametervalue[3];
    //alert(solarvoltage);

    var iframe;
    iframe=document.getElementById('iframe1');
    alert(iframe.src);
    iframe.src=iframe.src+ '?' + parametervalue[1] + '&' +parametervalue[2] + '&' + parametervalue[3];
    alert(iframe.src);

  13. #28
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,154
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles