Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

How can I still process an HTML form in PHP without the name of each input? 

let's say i want to use the 'id' option

for example

<pre><html>
<body>

<form action="welcome.php" method="post">
Name: <input type="text" id="name"><br>
E-mail: <input type="text" id="email"><br>
<input type="submit">
</form>

</body>
</html>


If I do
<?php echo $_POST["name"]; ?>


it won't print anything!

Thanks in advance.

What I have tried:

Hi all,

How can I still process an HTML form in PHP without the name of each input? 

let's say i want to use the 'id' option

for example

<pre><html>
<body>

<form action="welcome.php" method="post">
Name: <input type="text" id="name"><br>
E-mail: <input type="text" id="email"><br>
<input type="submit">
</form>

</body>
</html>


If I do
<?php echo $_POST["name"]; ?>


it won't print anything!

Thanks in advance.
Posted
Updated 21-Mar-18 4:26am
Comments
ThilinaMD 21-Mar-18 8:20am    
For $_POST and $_GET you have to use name attribute to get the value. You can use ajax to process data if you want to use id attribute instead of name attribute

$_POST["name"] can be only used in the page that is called upon submitting the form (welcome.php in your case).

If a page is called without parameters, the PHP: $_POST - Manual[^] array is always empty.

If you need access to PHP parameters within the page that contains the form, you have to use a single file for it (that is: the form action attribute points to it's own URL). Then check with isset() if it has been called with or without parameters (by submitting or by opening the URL) and act accordingly.
 
Share this answer
 
Your really don't need to be using a form at all if you're not going to be using the forms built-in method to transfer data to the target file.

Use AJAX [^] - once I got used to AJAX, I very rarely ever used a form, again.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900