1

I try open url from user input value but its no value

<form>
<p>*number:</p>

  <input type="text" name="numberpage" value=""/>

</form>
<a  href="./page.php?page=editdatapo&id=<?php echo $_POST['numberpage']; ?>">find</a>

here result that should be

user input = 13

output url

localhost/page.php?page=editdatapo&id=13

but output like this

localhost/page.php?page=editdatapo&id=

2
  • 2
    Add method="post" in <form> tag and add a submit button to post form Commented Apr 6, 2021 at 5:43
  • 1
    or you can use jquery to change link id value on user input event as well Commented Apr 6, 2021 at 5:45

2 Answers 2

5
<form action="./page.php" method="GET">
   <p>*number:</p>
   <input type="hidden" name="page" value="editdatapo" />
   <input required type="text" name="id"/>
   <input type="submit" value="Find" />
</form>

Try using GET. After hitting submit, it will redirect to:

page.php?page=editdatapo&id=USER_INPUT

This way, you dont have to use $_POST just to access the link. You can just type the id then hit Enter/Find directly.

By default, forms without the method attribute uses GET and you can omit it if you really want to.

Sign up to request clarification or add additional context in comments.

3 Comments

By default form method is always get so no need to write it
Thanks @ServingQuarantineperiod. I just wanted to emphasize that the form will be using GET. It is better markup on my opinion too. Updated my answer.
Your approach is totally fine, but it will work perfectly without writing it, because it's by-default
3

Here is a working code without page refresh:

<form>
   <p>*number:</p>
  <input type="text" id="numberpage" value=""/>
</form>
<a href="#" id="findAnchor" onclick="handleAnchorClick()">find</a>

<script>
    function handleAnchorClick(){
        const inputVal = document.getElementById('numberpage').value;
        alert(`./page.php?page=editdatapo&id=${inputVal}`);
        window.location.href = `./page.php?page=editdatapo&id=${inputVal}`;
    }
</script>

Comments

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.