Solution 1 :

As hassan said , you can do this only with javascript.
This will redirect to the url what you desired.

document.querySelector("form").onsubmit = function(){

For example
If document.querySelector("[name=peyid]").value = 12345678901234 The url will look like

So if you just need to redirect to that url you don’t even need form just

<input type="text" id="peyid" name="peyid" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(..*?)..*/g, '$1');" maxlength="14" ><br><br>
<input type="button" value="submit">

    document.querySelector("[type=button]").onclick = function(){
        location.href = `${document.querySelector("[name=peyid]").value}`;

Solution 2 :

Using PHP—to receive a form value, validate it, apply it to a URL, and redirect the client to that location, use $_POST, preg_match(), string interpolation, and header().



if ( isset($_POST['peyid']) && preg_match("/^d{14}$/", $_POST['peyid']) ) {



<html><head><title>oops</title></head><body>An error occurred.</body></html>

Problem :

I have a question from php and I’m not expert in php.

1.I have html page with one form include a text box and submit button .

2.I have a static target url like this :

XXXXXXXXXXXXXX is just numbers and has 14 characters.

*** What I need is that my customer enter its 14 characters number in input text form and when it submit , goes to target url.I want to check input form for entry numbers too.

I make a sample form like this but not work:

        <form action="" class="pey-form" method="get">
          <input type="text" id="peyid" name="peyid" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(..*?)..*/g, '$1');" maxlength="14" ><br><br>
          <input type="submit" value="submit">

What can I do?


Comment posted by hassan

It has nothing to do with PHP in this case, use javascript to listen to the form submission, and on submit append the input value to the form action URL.

Comment posted by brombeer

Could submit to a php script to check/validate your input, then redirect to the desired page/url

Comment posted by Hadi

how i can do it? i’m not so expert

Comment posted by Hadi

Thanks, the second part work for me as well. just how I can set a condition for empty text box that give an error or not work?

Comment posted by dollar

You can simply use if else to make it. like

Comment posted by$