I am hoping my explanation of this is clear enough...
Say I have an iframe in one page using src "http://potternet.duoservers.com/%3Faction=f_order&plan_id=48174&css_file=htt://www.potternet.net/css/form.css&otype=", how would I use links from other pages of my site to change the "plan_id=" part to show a different number in each case?
I figure that my links from other pages can be to "set-up-hosting.html?[relevant id number]" in each case.
the question is, can I replace "plan_id=48174" with something like "plan_id=$plan" and use jquery to write the relevant number from the querystring of a link from another page of my site?
Give your iFrame and ID and update the src attribute.
Here is a simple example of update the iframe's src value. the value for "a=1" could be whatever you want... URL param, from another field on the page, etc.
Bearing in mind that i have 20-odd links, the only difference between any and all of them is that specific ID number. I have tried passing the complete URL as a querystring to the iframe using jquery but it doesn't URLencode the querystring that is a part of the URL I want loaded in the iframe. I thought it might be easier to replace the "ID=[number]" with "id=$plan" and have jquery get the querystring from a link on another page and write it as $plan into the link... can that be done?
I figured out that this will be better served by using php. Investigating now. If anyone has any suggestions, let me know but my idea involves having "plan_id=<?php echo $plan ?>" in the link and having some kind of PHP code in the head of the HTML that will read the ID number from the querystring of the link that lead to the page. The question is, what would I need in the programming in the head of the page? lol
each one where the "plan_id" is the only difference.
Can I set each link up on their respective pages so that I can just have a simple querystring (ie. my-page-name.html?41745 or my-page-name.html?36906, etc) that will pass the number from the query string of the web address to the iframe that the form would load up in?
Is there a jquery code I can place into the head of my page to "$GET" the querystring and then get the iframe to load up with the correct information each time?
Should you need a better explanation, let me know and I will see what I can do. cheers
If you are using PHP for your server-side language, my recommendation is to let PHP create the URL for the iFrame for you. (PHP can read query string params just fine, so you can easily put that param's value in your iframe's URL.
If you must use javascript code to update the iframe's URL, neither javascript nor jQuery offer out of the box access to specific URL parameters, but there are lots of code snippets available out there for you to use. For example, combined with the code I posted above for updating the src of the iframe, you could use the function found here to get a value from the URL which you could use: http://www.jquery4u.com/snippets/url.../#.T98bMJF6Tbw
OK. Then I will stick to finding a way to do it in PHP as that seems like a better idea seeing as the only difference between all the links is that number. I have posted a request in the PHP forum for this so if anyone cal help me out with it, please take a look @
Note: The query string comes AFTER the URL and BEFORE the ID .
3. In either case, the plan ID could be read by the Iframe page something like:
<body>
<?php
/* suppress notice if data not found */
error_reporting(E_ALL ^ E_NOTICE);
/* check for plan ID */
if ( $_GET['plan_id'] == NULL ) { $plan_id='default'; }
else { $plan_id=$_GET['plan_id'];
} ?>
Note: I've included code to set a default plan ID in case one is not supplied, and suppressed the error warning that arises if you GET a NULL variable.
4. You then use $plan_id in the Iframe as you suggested...
Note: In case you are not aware, you cannot test PHP code using your browser, (like you can with HTML). You need to set up a local host. I recommend wamp.
OK. Firstly, I have found a link that is far easier to use for the purpose. It cosists of "extrnal.url/order?plan=44944".
Now, how do I pass the "plan=44944" from a querystring in the URL that lead to the page with the iframe in it. (ie. Link from other page my-page.html?plan=44944)
(ie.
Code:
<iframe src="http://external.url/order?[value from querystring]"
)
How would I use some kind of jquery to read the querystring from the "my-page.html?plan=44944" and get the iframe to load it as "http://external.url/order?plan=44944" but then have it work with other plan numbers (ie. link "my-page.html?plan=50934" gets iframe to load "http://external.url/order?plan=50934") and this works no matter what the "plan=" number is...?
I hope that this makes sense to someone as I am having issues writing it in a way that seems clear and concise. lol
OK. Firstly, I have found a link that is far easier to use for the purpose. It cosists of "extrnal.url/order?plan=44944".
Now, how do I pass the "plan=44944" from a querystring in the URL that lead to the page with the iframe in it. (ie. Link from other page my-page.html?plan=44944)
(ie.
Code:
<iframe src="http://external.url/order?[value from querystring]"
)
How would I use some kind of jquery to read the querystring from the "my-page.html?plan=44944" and get the iframe to load it as "http://external.url/order?plan=44944" but then have it work with other plan numbers (ie. link "my-page.html?plan=50934" gets iframe to load "http://external.url/order?plan=50934") and this works no matter what the "plan=" number is...?
I hope that this makes sense to someone as I am having issues writing it in a way that seems clear and concise. lol
Using PHP would be way easier in my opinion:
PHP Code:
<?php //sanitize the variables first if(!isset($_GET['plan']) || !is_numeric($_GET['plan'])){ //do something here cause it is an error in the data } else { //somewhere in your code you want the iframe ?> <iframe src="http://external.url/order?plan=<?php echo $_GET['plan'];?>> <?php } ?>
<?php
//sanitize the variables first
if(!isset($_GET['plan']) || !is_numeric($_GET['plan'])){
//do something here cause it is an error in the data
} else {
//somewhere in your code you want the iframe
?>
<iframe src="http://external.url/order?plan=<?php echo $_GET['plan'];?>>
<?php } ?>
Ok... Your comments within the PHP code have confused me somewhat as I haven't done anything PHP related before now. If I am right, the code would look like this:
[PHP]
<?php
if(!isset($_GET['plan']) || !is_numeric($_GET['plan']))
{ (what would go here??)
}else
{ (what would go here??)
}
?>
Am I correct? And can you append the details where I have asked the question of "What would go here??" please? Thank you
Additional: The link leading to the page with the iframe would read "my-page.html?plan=49444" or whatever number in each case and the PHP would read this and input it into the link for the iframe source before it loads the iframe contents, correct?
OK. Firstly, I have found a link that is far easier to use for the purpose. It cosists of "extrnal.url/order?plan=44944".
Now, how do I pass the "plan=44944" from a querystring in the URL that lead to the page with the iframe in it. (ie. Link from other page my-page.html?plan=44944)
(ie.
Code:
<iframe src="http://external.url/order?[value from querystring]"
)
I've already answered this. My solution may seem complex but that is simply because I've included error handling and how to handle "/" and "#". In principle it's just:
In the calling page(s):
<a href= "my-page.php?plan=449444">text</a>
In the iframe page:
$plan=$_GET['plan']
and:
<iframe src="url/form_<?php echo $plan; ?>.ext">
Assuming the plan id is part of the name of the form you want to display.
Originally Posted by PotterNet
How would I use some kind of jquery to read the querystring from the "my-page.html?plan=44944" and get the iframe to load it as "http://external.url/order?plan=44944" but then have it work with other plan numbers (ie. link "my-page.html?plan=50934" gets iframe to load "http://external.url/order?plan=50934") and this works no matter what the "plan=" number is...?
I hope that this makes sense to someone as I am having issues writing it in a way that seems clear and concise. lol
You should not use JavaScript (or Jquery) for essential functionality. Not all web-aware devices support them. Use PHP. It is transparent to the client because it is done by the server. I.e. So long as your web server supports PHP, it works everywhere.
P.S. Criterion9's solution is essentially the same as mine.
I've already answered this. My solution may seem complex but that is simply because I've included error handling and how to handle "/" and "#". In principle it's just:
In the calling page(s):
<a href= "my-page.php?plan=449444">text</a>
In the iframe page:
$plan=$_GET['plan']
and:
<iframe src="url/form_<?php echo $plan; ?>.ext">
Assuming the plan id is part of the name of the form you want to display.
You should not use JavaScript (or Jquery) for essential functionality. Not all web-aware devices support them. Use PHP. It is transparent to the client because it is done by the server. I.e. So long as your web server supports PHP, it works everywhere.
P.S. Criterion9's solution is essentially the same as mine.
Firstly: My pages are ALL .HTML documents.
Secondly: I tried your approach using
PHP doesn't by default parse html documents (usually has a .php extension). Do you have the ability to use PHP scripting with your current configurations?
Bookmarks