Click to See Complete Forum and Search --> : Calling file from a form
MasterDucky
January 21st, 2011, 01:52 PM
When you call a .php file from a html form is there a way to not open a
new window just execute the file?
<form action=guess.php method=post >
<input type="text" id="film" name="film"><br><br>
<input type="submit" name="theinput" value="Check!">
</form>
I want to call a popup window from guess.php if the condition is true, tested in guess.php, but i dont want guess.php to open a new window.
I tried the 'target=' method but it didnt work and they say it's depricated too.
PeejAvery
January 21st, 2011, 02:09 PM
If you don't include the target property in the <form> tag, then it will open in the same window, not a new one.
And, all HTML tags require double quotes around property values. Your form tag is invalid.
MasterDucky
January 22nd, 2011, 01:29 AM
Thank you Peej!
Indeed without the target property it opens in the same window and i missed the quotes around the property values.
But what i'd like to do is to call guess.php from index.php but keep index.php displayed.
Yes i know that i can just include("index.php"); at the end of guess.php but is it the right way to do it?
PeejAvery
January 22nd, 2011, 05:26 AM
Don't include index.php at the end! Redirect back to the sender. As long as there's no output, it won't even seem like it was sent to a different for for processing.
header ('Location: index.php');
Personally, it's better to have the current page do the form processing, that way, there isn't a redirect. Here's an example...
<?php
if (isset($_POST['firstname'])) {
// posted data is detected...process the form data
}
?>
<form method="post" ... >
<input name="firstname" ... />
MasterDucky
January 22nd, 2011, 06:24 AM
The problem with redirection is that even if header() is at the end of the file, it wont process anything in the file before itself, it just redirects.
As far as to have the current page do the form processing i wanted to avoid to get the index.php file too big but if there is no other option i will process it there.
PeejAvery
January 22nd, 2011, 09:00 AM
As far as to have the current page do the form processing i wanted to avoid to get the index.php file too big but if there is no other option i will process it there.
If you really have an aversion to large files, you shouldn't be in the coding business. That's what happens...and it's one of the reasons why code commenting exists.
Second, just use an included file if you really have to have your code separate. Just include it right before the form.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.