Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New Coder
    Join Date
    Mar 2013
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation Button link redirecting to WRONG location

    I set my button link up like this <button type="submit" onclick="document.location = 'HERE.php';"><span>Click Me</span></button>

    When clicked Instead of going to mywebsite.com/HERE.php it goes to mywebsite.com/INDEX.php which is my homepage. At first i did not notice anything on chrome but when i went on IE i noticed that it redirected me to my HOMEPAGE instead of the page i wanted to go to. Then i tried it on Chrome and it did the same thing as IE did. So Chrome was taking me to HERE.PHP at first but then it startd redirecting me to INDEX.php. I have no idea why it is doing thi. I am using PHP can anyone tell me why i am being redirected to the wrong page

    Notice in my coding i put onclick = HERE.php not onclick = INDEX.php so why is it taking me to my Index(homepage)

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    A submit button is designed to submit a form and would go to whatever is set as the action attribute of the form, or back to the current page.

    Use an ordinary button, without the type="submit" attribute. You don't need the additional SPAN either.

    Your button only links to a page, so why not use an A-link? you can use CSS to make it look like a button.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    New Coder
    Join Date
    Mar 2013
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by AndrewGSW View Post
    A submit button is designed to submit a form and would go to whatever is set as the action attribute of the form, or back to the current page.

    Use an ordinary button, without the type="submit" attribute. You don't need the additional SPAN either.

    Your button only links to a page, so why not use an A-link? you can use CSS to make it look like a button.
    I don't know how to do that. Would you please explain? I am not an expert in CSS

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Assuming you give your a-link the class "button" then you could explore css such as:

    Code:
    .button {
        font: bold 11px Arial;
        text-decoration: none;
        background-color: #EEEEEE;
        color: #333333;
        padding: 2px 6px 2px 6px;
        border-top: 1px solid #CCCCCC;
        border-right: 1px solid #333333;
        border-bottom: 1px solid #333333;
        border-left: 1px solid #CCCCCC;
    }
    which I just copied from a web-page.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #5
    New Coder
    Join Date
    Mar 2013
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Something is seriously wrong with my website. I don't think it has anything to do with the page itself as i once thought. Let me explain, So i just set up this new page in Hostgator Cpanel named ''newpage.php'' I went back in my coding and changed a button redirection from one page ''OnePage.php'' to the new page URL ''newpage.php'' The coding for that is as i stated before
    Originally was
    <button type="submit" onclick="document.location = 'ONEPAGE.php';"><span>Next Step</span></button>
    Now is
    <button type="submit" onclick="document.location = 'NEWPAGE.php';"><span>Next Step</span></button>
    'Document.location = Was changed from my old page to my new one

    As i mentioned earlier the button is NOT taking me to my new page i just created instead it is taking me to Index.php even though the document location in the code points to my new page. As i said earlier this is mainly evident on IE and not Chrome but now even Chrome is showing the same thing.

    So i did a test. I went to my homepage and TYPED in the url of NEWPAGE.PHP (http://www.mydomain.com/NEWPAGE.PHP) an clicked enter. to my amazement i was sent to my Index.php (homepage) instead of going to the actual page. I tried again and the same thing happened until after 3 tries it went to the page at last. So i see now it is not the button but the page. It has only been recently created and is NOT allowing entrance from redirection from the button or from direct url input (Atleast not until a few tries)

    Do you know why this is?

  • #6
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    727
    Thanks
    20
    Thanked 85 Times in 85 Posts
    Change button type from submit to button
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,421
    Thanks
    62
    Thanked 535 Times in 522 Posts
    Quote Originally Posted by AndrewGSW View Post
    A submit button is designed to submit a form and would go to whatever is set as the action attribute of the form, or back to the current page.

    Use an ordinary button, without the type="submit" attribute.
    Quote Originally Posted by AndrewGSW View Post
    Assuming you give your a-link the class "button" then you could explore css such as:

    Code:
    .button {
        font: bold 11px Arial;
        text-decoration: none;
        background-color: #EEEEEE;
        color: #333333;
        padding: 2px 6px 2px 6px;
        border-top: 1px solid #CCCCCC;
        border-right: 1px solid #333333;
        border-bottom: 1px solid #333333;
        border-left: 1px solid #CCCCCC;
    }
    Quote Originally Posted by yoursisless View Post
    Something is seriously wrong with my website.
    Originally was
    <button type="submit" onclick="document.location = 'ONEPAGE.php';"><span>Next Step</span></button>
    Now is
    <button type="submit" onclick="document.location = 'NEWPAGE.php';"><span>Next Step</span></button>
    'Document.location = Was changed from my old page to my new one

    As i mentioned earlier the button is NOT taking me to my new page i just created instead it is taking me to Index.php even though the document location in the code points to my new page.
    It's not so much something wrong with your website as it is something is wrong with you

    You've been given strong advice not to use the submit button. You've ignored this.

    Why have you not taken this advice onboard?

    In html forms, there are two types of button (well three if you include the reset):
    1) Submit
    2) Button

    The submit will submit a form to the action url. The onclick event is tempermental when used with the submit button and from vague memory works best with a function that returns a true or false result.

    The button does not submit the form but will trigger any javascript code you assign with ease. While I'm not overly sure about the previous suggestions for implementing a button, this is the way I've always done it:

    <input type="button" name="mode" value="Do Something" onclick="dosomething();">

    Note that I use the input declaration instead of button. Then for the type I use button instead oif submit. Thats just the way I've always done it as I never knew you could use button with a type however the way I do it has always worked well for me.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #8
    New Coder
    Join Date
    Mar 2013
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    It's not so much something wrong with your website as it is something is wrong with you

    You've been given strong advice not to use the submit button. You've ignored this.

    Why have you not taken this advice onboard?

    In html forms, there are two types of button (well three if you include the reset):
    1) Submit
    2) Button

    The submit will submit a form to the action url. The onclick event is tempermental when used with the submit button and from vague memory works best with a function that returns a true or false result.

    The button does not submit the form but will trigger any javascript code you assign with ease. While I'm not overly sure about the previous suggestions for implementing a button, this is the way I've always done it:

    <input type="button" name="mode" value="Do Something" onclick="dosomething();">

    Note that I use the input declaration instead of button. Then for the type I use button instead oif submit. Thats just the way I've always done it as I never knew you could use button with a type however the way I do it has always worked well for me.
    I have already tried this and it didn't work on IE which is a huge source of traffic. Although it worked on Chrome i am still worried about my IE users. I have removed the submit code and made it a regular button code here it is
    <input type="button" onclick="document.location = 'NEWPAGE.php';"><span>Click Me</button>

    On chrome it works but on IE it does not. Also it's fundamental to note that i am using a really old version of IE as a test (Basic IE that comes with a basic Windows 7 computer)

    What i do not understand is why it is not taking me to NEWPAGE.PHP but INDEX.php I can even type it on my browser and in seconds i will be on my homepage instead of the page i want to be on (Newpage.php) So even when typed it does not take you there (This is mainly all on IE btw) Ever since i removed the submit code you suggested it has been working on Chrome but i don't know if it's cookies making it work just for me while others could be having the same problem as if they were on IE

  • #9
    New Coder
    Join Date
    Mar 2013
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    <form action="NEWPAGE.php" method="post" name="name_01">
    input type="hidden" name="type" value="01">
    <input type="submit" class="select-button" value="Name Me" title="Name Example"/>

    I am getting 'Error on page'' on Internet explorer. Also my Chrome users are having trouble. What was wrong with that code? Oh and i am not still using it i just want to know why IE is saying there is an error on the page

  • #10
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,421
    Thanks
    62
    Thanked 535 Times in 522 Posts


    Quote Originally Posted by tangoforce View Post
    onclick="dosomething();"
    I'm no JS expert but as far as I know, you can't run actual code in there, you can only call a FUNCTION and that is exactly what I showed you
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #11
    New Coder
    Join Date
    Mar 2013
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post




    I'm no JS expert but as far as I know, you can't run actual code in there, you can only call a FUNCTION and that is exactly what I showed you
    My interest is no longer in that my recent postings explain that i am redirected to index.php (homepage) even when directly typed in browser, so as you can imagine button redirection will produce the same result. What i want to know is how i can change it so it goes to newpage.php instead of index.php both when directly typed in browser and redirected by button

  • #12
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    727
    Thanks
    20
    Thanked 85 Times in 85 Posts
    You need to check your .htaccess file for a redirect

    We can only assist you with things we can write.

    Sounds like a phone call to your host would be a good place to start.
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #13
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,421
    Thanks
    62
    Thanked 535 Times in 522 Posts
    Quote Originally Posted by yoursisless View Post
    My interest is no longer in that my recent postings explain that i am redirected to index.php (homepage) even when directly typed in browser, so as you can imagine button redirection will produce the same result.
    Correct me if I'm wrong but I don't actually see where you've mentioned that anywhere. All I see you talking about is the buttons and when we have tried to correct you, you've either ignored us or ignored us.

    Now you're saying that isn't the problem and its a url problem that is redirecting only certain browsers?

    Have you even tried any of our suggestions?

    If you'd like to give us the url perhaps we can see an example of this in action.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #14
    New Coder
    Join Date
    Mar 2013
    Posts
    19
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    Correct me if I'm wrong but I don't actually see where you've mentioned that anywhere. All I see you talking about is the buttons and when we have tried to correct you, you've either ignored us or ignored us.

    Now you're saying that isn't the problem and its a url problem that is redirecting only certain browsers?

    Have you even tried any of our suggestions?

    If you'd like to give us the url perhaps we can see an example of this in action.
    Apologies if i did not make that clear enough but i have been trying everything you said.

  • #15
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,421
    Thanks
    62
    Thanked 535 Times in 522 Posts
    Quote Originally Posted by yoursisless View Post
    Apologies if i did not make that clear enough but i have been trying everything you said.
    Including showing us a url
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

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