|
-
January 21st, 2011, 02:52 PM
#1
Calling file from a form
When you call a .php file from a html form is there a way to not open a
new window just execute the file?
PHP Code:
<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.
-
January 21st, 2011, 03:09 PM
#2
Re: Calling file from a form
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 22nd, 2011, 02:29 AM
#3
Re: Calling file from a form
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?
Last edited by MasterDucky; January 22nd, 2011 at 03:32 AM.
-
January 22nd, 2011, 06:26 AM
#4
Re: Calling file from a form
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.
PHP Code:
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 Code:
<?php if (isset($_POST['firstname'])) { // posted data is detected...process the form data } ?>
<form method="post" ... > <input name="firstname" ... />
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
January 22nd, 2011, 07:24 AM
#5
Re: Calling file from a form
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.
-
January 22nd, 2011, 10:00 AM
#6
Re: Calling file from a form
 Originally Posted by MasterDucky
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.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|