How to open iframe on the same page - php

What I need, I have xxx.php webpage which connect to PostgreSQL DB, send some query and result is displayed inside the iframe. Then I have simple yyy.html page where I have form for searching inside DB, but I want to open iframe on the same page (after sql query is done), not by opening another page. Is that possible to do it? It works in my case just by creating another page.
I hope it is clear.
Thank you
<?php
$kpc = $_POST["kpc"];
$ku= $_POST ["ku"];
<body>
<script>
function klik(){
document.getElementById("maps").innerHTML = '<object type="text/html" data="xxx.php" ></object>';
}
</script>
<form action="datab.php" method="post">
text: <input type="text" name="kpc"><br>
text2: <input type="text" name="ppc"><br>
<input type="Submit" id="submit">
</form>
<iframe id="maps">
</iframe>
</body>

The content of an iframe element is alternative content to display if iframes are not supported.
If you want to display content on the same page, then don't use an iframe.
<object type="text/html" is more-or-less the same as an iframe anyway. You could just not use that:
document.getElementById("maps").src = "xxx.php";
… for that matter you could remove the JavaScript and just submit the form directly to the frame:
<form action="xxx.php" target="name_of_iframe">

Related

Html Post Method get blank page after refresh

I am testing Html form using post method and got this odd result:
I have two html pages on server apache (already installed php): post.html and target.html, and the code for these page are followings:
post.html (don't worry about the html standard)
<div style="text-align: center">
<form method="POST" action="target.html">
<input type="text" name="testname" value="sometext" />
<input type="submit" value="submit" />
</form>
</div>
and target.html
<html>
<head>
</head>
<body>
<h1>Target page</h1>
</body>
</html>
When I entered data to the form on post.html page and hit submit button, I got to the target.html page. When on this page(target.html), I refreshed the page, and what I receive is a blank page. The second time I refreshed, It turned to normal Html page.
I don't know why it returned a blank page the first time I refreshed, I have tried the same approach but with PHP page, and the content of target page (assum name target.php) still remains (not blank like html files above)
So, could you explain me about this problem?
Thank you.
This definitely has something to do with your browser. Same here on a mac using Safari, on some pages after submitting the content, the page seems to freeze, I refresh it, and then it works again.
Definitely not a code problem, as far as I'm concerned.
It's because you cannot pass an input from html to html file. Your target.html should be a php file (target.php).
and try to put this code on your target.php
<?php
var_dump($_POST); //this will show the inputted text and also show the data type and will stop the code execution here. other codes below will not be executed.
echo $_POST['testname'];
?>
Additionally, change target.html to target.php in your form action
First I will start out by correcting your post.html
<div style="text-align: center;"> <!-- added a ; after center -->
<form method="POST" action="target.html">
<input type="text" name="testname" value="sometext" />
<input type="submit" value="submit" />
</form>
</div>
that may not matter but you should end all your styles with ;
To continue, everything looks fine. maybe something weird happened between refreshes.
save your form page in php than add the php script in the same page, here try this. remember save in .php.
<?php $testname = $_Post['testname'];
echo $testname ?>
<div style="text-align: center">
<form method="POST" action="">
<input type="text" name="testname" value="sometext" />
<input type="submit" value="submit" />
</form>
</div>

I need a way to auto resize an iframe, it isnt working from whatever I looked up hear or anywhere else [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Resizing an iframe based on content
What I am trying to do is:
Use a div to post a form to as an alternative to using ajax as there are some things that I need that are not working with ajax. My code is below for the 2 pages I am using:
The page with the form:
<form action="iframe.php" method="post" onsubmit="document.getElementById(\"\")" target="my_iframe">
<input type="hidden" name="post" value="postdata" />
<input type="submit" value="Do Stuff!" />
</form>
<!-- when the form is submitted, the server response will appear in this iframe -->
<iframe frameborder="0" name="my_iframe" id="frame" src="iframe.php"></iframe>
The iframe source:
<?php
if(isset($_POST['post'])){
var_dump($_POST);
}
?>
What can I do about this? Thanks in advance!
Start with your iframe being hidden in CSS with:
#frame {display:none}
.visible {display:block}
Then something like this on the submit button:
onclick="$(#frame).addClass('visible');"
This will work regardless of what the form does, though, so if you have validation, the frame will still become visible each time the button is clicked. If you rather, you can toggle it on and off with each press, like this:
onclick="$(#frame).toggleClass('visible');"
MuqMan good to see you again! You can change the size of an iframe using its properties. You can then use JavaScript or PHP, depending on what or how you are determining the auto resize, to give a dynamic number to them.
The attributes you're looking for:
<iframe height="200" width="200"></iframe>
iframe properties http://www.w3schools.com/tags/tag_iframe.asp
If you're wanting to show an iframe after the click, you will want to use a change source event of the iframe.
Here's a starter for you iFrame src change event detection?

How can I get a file I selected in a file select control in file1.html, trough javascript, into file2.php to be processed

The structure looks like this:
<form>
...
some stuff
...
file select
...
some stuff
...
</form>
I need to send the input data from "file select" while not sending "some stuff" and as far as i've tried I couldn't get a form inside another form so that's not an option.
The way it works is like this: the file select control isn't displayed at first, clicking a button makes it show the control and some other stuff. I need a button to submit that file to be checked for different things (naming, size, etc) and uploaded to the server, without changing or reloading the rest of the window.
I could change the layout a bit and get the file select stuff out of the form but the boss doesn't want to change the design of the window and removing the outer-most form will be a lot of work as it's a very complicated part of the web site.
So, as the question says: Can I do it? Can I get the file trough javascript and send it to another php file for processing?
The most browser compatible way to achieve this is to use a hidden iframe that you submit the form into. For example:
<iframe name="my_iframe" id="my_iframe" style="display: none;"></iframe>
<form action="/next_step.php" method="post" target="my_iframe" entype="multipart/form-data">
<input type="file" name="file_upload" />
<input type="button" id="upload_btn" value="Upload file" />
<label for="name">Name</label>
<input type="text" name="name" id="name" />
<input type="submit" value="Next step" />
</form>
<script type="text/javascript">
var btn = document.getElementById('upload_btn');
btn.onclick = function(){
var form_elem = document.forms[0];
// direct file uploads through the hidden iframe
form_elem.action = '/test_file.php';
form_elem.target = 'my_iframe';
// submit the form
form_elem.submit();
// now reset for next step in the form
form_elem.action = '/next_step.php';
form_elem.target = null;
};
</script>

Using PHP Form to Embed Video

I want to use a PHP form to embed a video onto a web page. Not sure why this isn't working as the page source has the embed code but nothing is showing up on the page. Here's the PHP I'm using:
test.php
<html>
<head></head>
<form action="" method="post">
Embed Code: <input type="text" name="embedCode" />
<input type="submit" />
</form>
<?php echo $_POST['embedCode']; ?>
</html>
The 'embedCode' should be able to handle any generic video embedding code such as or and shouldn't be specific to YouTube or anything else.
The URL part must be the src of the embed. For a youtube video it would be like this:
<html>
<head></head>
<form action="" method="post">
URL: <input type="text" name="url" />
<input type="submit" />
</form>
<iframe width="560" height="315" src="<?php echo $_POST['url']; ?>" frameborder="0" allowfullscreen></iframe>
</html>
That should work. There are a few problems with this simple solution though:
you're trying to echo something that doesn't exist in most cases (when the page is loaded without the form being posted) -> check if the the form has been posted first
there is no input validation on what links are posted. You might want to make sure it's a valid (youtube?) link that's being posted before embedding it
Cheers
In your code there is a quote missing
<?php echo $_POST['url]; ?>
should be
<?php echo $_POST['url']; ?>
And for embeding a video if you just echo the url, it is not gonna embed.
You have to use the embed code for whatever kind of video it is for eg: Flash Player for flv/Flash Stream,WMP for wmv/asf streams,etc
You have to use the embed code and echo the url in the place were url is in the embed player

Loading form values from one IFrame to another

What I want to achieve is the following. A search is made from one IFrame "the form is loaded into this frame via the src atribute of iframe" the search query is then passed to another IFrame that redirects to a url with the query eg. www.test.com/index.php?query=test
Is this possible?
Currently my code looks as such
<iframe src="abc.php" name="iframe1">
</iframe>
<iframe name="iframe2">
<?php
var_dump($_GET);
?>
</iframe>
abc.php contains the following
<form method="get" action="#" target="iframe2">
<input type="text" name="searchtype" id="searchtype" />
<input type="submit" value="submit">
</form>
Untested (don't have PHP installed on this machine).
You are passing your submission form back to itself, and loading the result into iframe2, which is why you just see that form again in the other frame. So what you need to do is put your form processing logic into a second .php file, instead of inside your iframe tags, and then have the form's action be abcd.php (or whatever) and keep the target as iframe2.
Try this.
<form method="get" action="<?php $_SERVER['PHP_SELF']?>" target="iframe2">
<input type="text" name="searchtype" id="searchtype" />
<input type="submit" value="submit">
</form>

Categories