CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    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.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    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.

  3. #3
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    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.

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    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.

  5. #5
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    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.

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: Calling file from a form

    Quote Originally Posted by MasterDucky View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured