SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Header not to go anywhere

    Hi is there a way that i can set header not go anywhere like the problem with this is that it still goes to the second header is there a way i can set if none do nothing exit? and else do the second header??
    PHP Code:
    <?php
    if ($_POST['agents']=="none")
    {
     
    header("location:#");
     exit;
      
    // header("Location: {$_SERVER['PHP_SELF']}");

     
    }
     else
     {
     
    header("location:http://www.xxxxxx.co.uk/tv/".$_POST['agents']."/index.php");    
     }
    ?>

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Just... dont send a header in the if section. If it's firing the trigger in the else section and you dont think it should, you've got a problem with your condition.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the problem is that the form action jumps to the action="agents_jump.php file which has the headers is there a way on the form select option to put if
    <option value="none">Select</option>
    dont jump to the form action page

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    if ($_POST['agents']=="none")
    {
     echo 
    "You didnt specify an agent.";
     exit;
     }
     else
     {
     
    header("location:http://www.xxxxxx.co.uk/tv/".$_POST['agents']."/index.php");    
     }
    ?>
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi i managed to just redirect to the same page. one problem thou because the form opens the link into a new tab it redirects same page into the new tab. is there a way to do if none keep on the same tab because the aim is i dnt really want to do anything if selected none stay on the same page is it possible? if so how can i try?
    thanks

    PHP Code:
    <?php
    if ($_POST['agents']=="none"){
          
    $last_page $_SERVER['HTTP_REFERER'];
          
    header("Location: $last_page");
    }
    else 
    header("location:http://www.estateagentsonfilm.co.uk/tv/".$_POST['agents']."/index.php");
    ?>

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Stop trying to redirect them somewhere? If you do NOTHING, then they will stay where they are. Default behavior.

    Train is coming down a railroad track, towards a switch. The switch is currently set to point the train to the north (current page), the other direction is to the east (index). In order to make the train go north..... dont touch anything :P
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah but if the option on the form has values i need to take me to the other page (agents_jump.php)
    like is there a way i can if none when click button check if value none?? make button dont do anything but if option has value then redirect to new agents_jump.php page cz i cnt figure how to
    PHP Code:
    <form id="agents" action="agents_jump.php" method="post" name="agents" target="_blank" style="margin:0;">
    <
    option value="none">Select</option>
    <
    option value="one">Select</option>
    <
    option value="two">Select</option>
                   <
    input class="view_agents" id="tvoption" type="image" src="images/viewagents.gif" alt="TV OPTION" name="tvoption"

  8. #8
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just try this script
    PHP Code:
    <?php
    if ($_POST['agents']=="none")
    {
     print 
    "<script>";
     print 
    " self.location='yourfilename.php'";
     print 
    "</script>";

     }
     else
     {
     print 
    "<script>";
     print 
    " self.location='http://www.xxxxxx.co.uk/tv/$_POST['agents']/index.php'";
     print 
    "</script>";    
     }
    ?>
    [/QUOTE]

  9. #9
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    You could add some Javascript to disable the button when 'none' is the option selected...or just put your code into the same page as that form, wrap it in a if isset $_POST['agents'], and then have the form action to itself.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  10. #10
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ritesh162 View Post
    just try this script
    PHP Code:
    <?php
    if ($_POST['agents']=="none")
    {
     print 
    "<script>";
     print 
    " self.location='yourfilename.php'";
     print 
    "</script>";

     }
     else
     {
     print 
    "<script>";
     print 
    " self.location='http://www.xxxxxx.co.uk/tv/$_POST['agents']/index.php'";
     print 
    "</script>";    
     }
    ?>
    And then as soon as someone without javascript enabled visits your site, your code stops working
    Yeah... no. Bad idea. When this can be accomplished using pure PHP, using javascript just makes it less effective.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  11. #11
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    And then as soon as someone without javascript enabled visits your site, your code stops working
    Yeah... no. Bad idea. When this can be accomplished using pure PHP, using javascript just makes it less effective.
    yeah that would previous script would work fine the problem would be still jumps into a new tab which is what i am trying to avoid i have also tried to avoid javascript but it seems like one of the choice would be

    PHP Code:
    <script type="text/javascript">
        function 
    checkAgent() {
            if (
    document.getElementById('agent_select').selectedIndex == 0) {
                
    alert('Please select an Agent');
                return 
    false;
            }
            return 
    true;
        }
     <
    form id="agents" action="agents_jump.php" onsubmit="return checkAgent();" method="post" name="agents" target="_blank" style="margin:0;">
                    
                        <
    select name="agents" size="1" style="width:160px; font-size:13px;">
                                                <
    option value="none">Select</option>
     <
    input class="view_agents" id="tvoption" type="image" src="images/viewagents.gif" alt="TV OPTION" name="tvoption"  border="0"   onclick="jwplayer().stop();">
    </script> 
    but even that function not working and i would still keep the header on the next file so if javascript disable it would simple redirect using the header
    so on the header page i would have
    PHP Code:
    <?php
    if ($_POST['agents']=="none"){    
          
    $last_page $_SERVER['HTTP_REFERER'];
          
    header("Location: $last_page");

    }
    else 
    header("location:http://www.xxxxx.co.uk/tv/".$_POST['agents']."/index.php");
    ?>
    but the javascript function is not even working do you know anything about javascript can you spot whats wrong with the above function that is not working??

  12. #12
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    if (document.getElementById('agent_select').selectedIndex == 0) {

    <select name="agents" size="1" style="width:160px; font-size:13px;">

    *hums* One of these things is not like the other....
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  13. #13
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    if (document.getElementById('agent_select').selectedIndex == 0) {

    <select name="agents" size="1" style="width:160px; font-size:13px;">

    *hums* One of these things is not like the other....
    yes i did try have the agents name and function name aswell but still send me to the action page from the form even when secet option none??

  14. #14
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    might have to be "onSubmit" rather than onsubmit, and you forgot to close your <script> tag.

    But you should be handling this from PHP. Have the form action set to '', and put the code you've got in agents_jump.php into the page you want to jump from, wrapped in if(isset($_POST['agents'])) { ... }
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  15. #15
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    on the submit button do i need to name name= submit too cz at moment the submit button is like this
    PHP Code:
      <input class="view_agents" id="tvoption" type="image" src="images/viewagents.gif" alt="TV OPTION" name="tvoption"  border="0"   onclick="jwplayer().stop();"

  16. #16
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,036
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    Stop trying to redirect them somewhere? If you do NOTHING, then they will stay where they are. Default behavior.

    Train is coming down a railroad track, towards a switch. The switch is currently set to point the train to the north (current page), the other direction is to the east (index). In order to make the train go north..... dont touch anything :P
    This isn't entirely accurate. Unless PHP is told to do otherwise it sends HTTP Header 200 Ok! and is supposed to send a new body.

    When a user gets a form wrong it is tradition to resent the form to the user with the bad field highlighted.

  17. #17
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Michael Morris View Post
    This isn't entirely accurate. Unless PHP is told to do otherwise it sends HTTP Header 200 Ok! and is supposed to send a new body.

    When a user gets a form wrong it is tradition to resent the form to the user with the bad field highlighted.
    Yes, when I say 'stay where they are', i meant the form processing page (which, in most cases, is the same page as the form, so that if the form IS bad, you dont have to 'go anywhere', you just let the form page reproduce itself.)
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  18. #18
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @start lion thanks for the help got what i've done is i set a javascript alert box when select option == none so stays on the same page but also left the action page with a header if select option equal none to redirect to the same page this way even if the javascript is disable will take to that page and do a similiar job thank you very much


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •