0

I have a form in my page and also have different phps in the same page..how can i pass the form to one of the phps? Thank you

It goes like this.

<form action = 'samepage.php' 
method='POST'>
<input>
<input type = 'submit'>
</form>
<?php 
?>
<?php 
?>
<?php
I want to pass the value here
?>
3
  • you have to set first a form input name then read it via $_POST, and removing the action will make it post to itself Commented Dec 21, 2020 at 7:57
  • 1
    once you POST the form whatever values there were in the form are available throughout that page. The input needs a name and can be accessed using $_POST['name_of_field'] Commented Dec 21, 2020 at 7:59
  • Keep in mind that all php blocks are always executed in order, one after another. I think that described approach is not the best one. I'd separate this php file into several separate ones. Commented Dec 21, 2020 at 13:34

1 Answer 1

1

The form in HTML page is a structure that allow you to insert some value and then can be passed to the backend with a specific HTTP Method called as GET,POST,PUT, DELETE etc.

Here an example:

// HTML Page. index.html
<form action="page.php" method="POST">
<input type="text" name="username">
<input type="submit">

// page.php
<?php
$username = $_POST['username'];

echo "Your username is: " . $username;
?>
Sign up to request clarification or add additional context in comments.

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.