Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8900297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:04:23+00:00 2026-06-15T01:04:23+00:00

I have a simple form: <form id=frm action=process.php method=post> <input type=text id=shortcut name=shortcut />

  • 0

I have a simple form:

<form id="frm" action="process.php" method="post">
    <input type="text" id="shortcut" name="shortcut" />
</form>

In process.php:

$gomenu = $_POST['shortcut'];
if(strpos($gomenu, "/") === 0) {
    //if $gomenu contains `/`, then it should open in new tab
    header('Location: newTab.php'); //--> How to open this into a new tab?
} else {
    header('Location: somePage.php'); //--> Redirect to somePage.php on the same tab
}

When the shortcut contains value of /, then it should be redirect to a new tab, else the same tab. How to do that? I know it’s impossible to do that by using header();, but I have no idea how to do that. Any ideas? Thanks.

PS: The form is intended to fill by a menu code, then it has to redirect the page based on the menu code filled on shortcut (as in SAP). But if it contains a specific prefix, a different way should be implemented.


UPDATE

Above the form, I’ve added this script:

<script>
    $("#frm").ajaxForm({
        url: 'process.php', type: 'post'
    });
</script>

And on the process.php:

$gomenu = $_POST['shortcut'];
if(strpos($gomenu, "/") === 0) {
    print   "<script>
                 window.open('newTab.php', '_newtab');
             </script>";
} else {
    header('Location: somePage.php');
}

But then it opened in a new pop-up window. How to open it on the newtab?


ANSWER (@fedmich’s answer)

        $(document).ready(function () {
            $('frm#frm').submit(function(){
                var open_new_tab = false;
                var v = $('#shortcut').val();
                if(v.match('/') ){
                    open_new_tab = true;
                }

                if ( open_new_tab ) {
                    $('frm#frm').attr('target', '_blank');
                } else {
                    $('frm#frm').attr('target', '_self');
                }
            });
        });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:04:24+00:00Added an answer on June 15, 2026 at 1:04 am

    I think you could do it this way, put the target blank by default.

    <form id="frm" action="process.php" method="post" target="_blank">
    
    </form>
    

    then when submitting on the form submit() and modify & navigate away if you need to.
    you could just use javascript before submitting, change the action or target attributes

    http://jsfiddle.net/fedmich/9kpMU

    $('form#frm').submit(function(){
        var open_new_tab = false;
        var v = $('#shortcut').val();
        if(v.match('/') ){
            open_new_tab = true;
        }
    
        if ( open_new_tab ) {
            alert('opening to new tab');
            $('form#frm').attr('target', '_blank');
            $('form#frm').attr('action', 'http://www.youtube.com');
        }
        else{
            alert('opening to self_page');
            $('form#frm').attr('target', '_self');
            $('form#frm').attr('action', 'http://www.yahoo.com');
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
I have a simple form like this : <form method=post name=change_pass id=change_pass action=change_pass2.php> <input
I have simple form: <form action=add.php method=post > <input name=name maxlength=30/><br/> <textarea cols=80 name=description
I have this simple form: <form ENCTYPE=multipart/form-data action=story.php method=POST> <input type=submit value=Show files> <input
I have such simple form in html: <form action=add method=get> <input name=ok type=submit value=ok
I have a simple form like this one: <form ENCTYPE=multipart/form-data action=upload.php method=POST> <p>UPLOAD FILE:
I have simple form set up like the following: <form> <input type=text name=first_number id=first_number
I have very simple form, with input like this: <input id=my_id multiple=true type=file name=image_name[]
I have a simple form and inside there are two input fields text type.
I have a simple form, e.g: HTML: Your favorite food? Pizza: <input type=checkbox name=food[]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.