0

I have a form that looks like this:

<form action="<?=getScriptUrl()?>?page=Confirm">
      <p><input class="w3-input w3-padding-16" type="email" placeholder="Email adress" required name="Email"></p>
      <p><input class="w3-input w3-padding-16" type="text" placeholder="Message subject" required name="Subject">
      <p><input class="w3-input w3-padding-16" type="text" placeholder="Message body" required name="Body">
      <p><button class="w3-button w3-light-grey w3-padding-large" type="submit" id = "submit-form">
        <i class="fa fa-paper-plane"></i>
        SEND TO ME
        </button>
    </form>

how do i create the query string ?page=confirm without sending the form data.

1 Answer 1

2

You can use this function to create a new query string.

const createQueryStringParameter = (uri, key, value) => {
  const regex = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
  const separator = uri.indexOf('?') !== -1 ? "&" : "?";
  if (uri.match(regex)) return uri.replace(regex, '$1' + key + "=" + value + '$2');
  else return uri + separator + key + "=" + value;
}

Usage:

createQueryStringParameter("localhost:8000","page","confirm"); //"localhost:8000?page=confirm"
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this worked exactly, thanks. I also needed to use <base target ="_blank">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.