Redrict a button to another site.

Results 1 to 11 of 11
  1. #1
    Valued Member GrateZ4 is offline
    MemberRank
    Jul 2014 Join Date
    145Posts

    happy Redrict a button to another site.

    I have a problem, i'm trying to make so a button updates the name and also redricts to another website at the same time you press the button but it only updates the name and doesnt redrict me to the website.

    Code:
    </div><button onclick="window.location.href='/me'" style="float:right" type="submit" value="account" name="language" class="button red medium submit">I'm done, Continue!</button><br></br>
    Maybe you guys have any idea how to make it update the php name and also redrict from the current site (language) to /me at the same time. The page just loads again if you click on the button.

    Thanks,
    Last edited by GrateZ4; 04-04-15 at 03:11 AM.


  2. #2
    Check http://arcturus.pw The General is offline
    DeveloperRank
    Aug 2011 Join Date
    7,608Posts

    Re: Redrict a button to another site.

    Code:
    onclick="window.location.href='/me'"
    To:

    Code:
    onclick="window.location.href='http://somesite.com/me'"
    ???

  3. #3
    Member Mink is offline
    MemberRank
    Jun 2011 Join Date
    55Posts

    Re: Redrict a button to another site.

    You don't need the onclick attribute, you can just call a redirect header in your update script after the name has been updated.

    PHP Code:
    <?php
    // your update language code here
    // if updated successfully { 
        
    header("Location: http://somesite.com/me");
        exit;
    // }

  4. #4
    Evil Italian Overlowrd Droppy is offline
    [Internal Coder]Rank
    Feb 2012 Join Date
    /home/droppyLocation
    2,080Posts

    Re: Redrict a button to another site.

    Quote Originally Posted by Mink View Post
    You don't need the onclick attribute, you can just call a redirect header in your update script after the name has been updated.

    PHP Code:
    <?php
    // your update language code here
    // if updated successfully { 
        
    header("Location: http://somesite.com/me");
        exit;
    // }
    He ain't looking for an website redirection, he's looking for button redirection. Like an <a href.
    @The General solution would be just fine.

  5. #5
    Check http://arcturus.pw The General is offline
    DeveloperRank
    Aug 2011 Join Date
    7,608Posts

    Re: Redrict a button to another site.

    I think he wants to update something first (POST) and then redirecting. Then you could use the header location in PHP to redirect.

    If OP could be more specific, that would be great.

  6. #6
    Member Mink is offline
    MemberRank
    Jun 2011 Join Date
    55Posts

    Re: Redrict a button to another site.

    Quote Originally Posted by The General View Post
    I think he wants to update something first (POST) and then redirecting. Then you could use the header location in PHP to redirect.

    If OP could be more specific, that would be great.
    Yeah, that's what I got out of reading it too. Pretty unclear.

    Quote Originally Posted by Droppy View Post
    He ain't looking for an website redirection, he's looking for button redirection. Like an <a href.
    @The General solution would be just fine.
    Actually, it would be most appropriate to handle the request server-side because he is sending form data, hence the name attribute. That's the very reason why it's not redirecting to where he wants it to but is updating the name/language, because he is sending a form.

    Consider the following (placeholder names, but you get the point):

    PHP Code:
    <form method="post" action="update-script.php">
    <
    button onclick="window.location.href='page-i-want.php'" type="submit" value="account" name="language">I'm done, Continue!</button>
    </form> 
    The onclick (redirect to page-i-want.php) is actually ignored, and instead goes to update-script.php. It would go where he wanted it to if he wasn't sending a form, but it would also not send his POST request. If you remove the form tags you can see this in action - it will go to "page-i-want.php", however it will not send any form data, therefore making his update name/language feature not work.

    Sending a redirect header in his PHP script would be the best bet for getting it to do exactly what he wants.

  7. #7
    Valued Member GrateZ4 is offline
    MemberRank
    Jul 2014 Join Date
    145Posts

    Re: Redrict a button to another site.

    edited to hide code.
    Last edited by GrateZ4; 04-04-15 at 03:48 PM.

  8. #8
    Member Mink is offline
    MemberRank
    Jun 2011 Join Date
    55Posts

    Re: Redrict a button to another site.

    Quote Originally Posted by GrateZ4 View Post
    This is how it looks like. i want that after the user has been choosing a language he should press the button "I'm done, Continue". and the language2 in the database should update and also redrict from the page "Language" to the me page. but it doesnt do the both at the same time. Now i just changed the form method and added action="me". now it redricts but doesnt update the language. and if i take away the action="me" it will update and not redrict :o
    In order to get it to do both, you're not going to need the action attribute nor the onclick on the button. Instead, you're going have to add a redirect header in the function that actually updates the language. Seeing as the code that actually does this is not in snippet you've posted here, I can't point out specifically where to do it. If you don't know where to put it exactly, feel free to post the corresponding code here so I can show you where it needs to go.

  9. #9
    Valued Member GrateZ4 is offline
    MemberRank
    Jul 2014 Join Date
    145Posts

    Re: Redrict a button to another site.

    Quote Originally Posted by Mink View Post
    In order to get it to do both, you're not going to need the action attribute nor the onclick on the button. Instead, you're going have to add a redirect header in the function that actually updates the language. Seeing as the code that actually does this is not in snippet you've posted here, I can't point out specifically where to do it. If you don't know where to put it exactly, feel free to post the corresponding code here so I can show you where it needs to go.
    There ya go :o
    Last edited by GrateZ4; 04-04-15 at 03:48 PM.

  10. #10
    Member Mink is offline
    MemberRank
    Jun 2011 Join Date
    55Posts

    Re: Redrict a button to another site.

    I would assume that the first snippet you posted was of from the /language page, considering that you said upon filling out the form they get sent back to the same page. The header defined in the function is doing just that, sending you back to /language when the user's language is succesffully updated.

    It's an easy fix. Replace:

    PHP Code:
    header('Location: '.$_CONFIG['hotel']['url'].'/language'); 
    with:

    PHP Code:
    header('Location: '.$_CONFIG['hotel']['url'].'/me'); 
    That should do the trick.

  11. #11
    Valued Member GrateZ4 is offline
    MemberRank
    Jul 2014 Join Date
    145Posts

    Re: Redrict a button to another site.

    Quote Originally Posted by Mink View Post
    I would assume that the first snippet you posted was of from the /language page, considering that you said upon filling out the form they get sent back to the same page. The header defined in the function is doing just that, sending you back to /language when the user's language is succesffully updated.

    It's an easy fix. Replace:

    PHP Code:
    header('Location: '.$_CONFIG['hotel']['url'].'/language'); 
    with:

    PHP Code:
    header('Location: '.$_CONFIG['hotel']['url'].'/me'); 
    That should do the trick.
    Yea i see, thanks for making me understand ;). Close thread



Advertisement