I am trying to get user input from a text box and then echo it using php. Here is my code, and it is not seeming to work.
<html>
<body>
<?php
echo $_POST['value'];
?>
<form method="post" action="">
<input type="text" name="value">
<input type="submit">
</form>
</body>
</html>
<html>
<body>
<?php
if(!empty($_POST['value']))
{
echo filter_var($_POST['value'], FILTER_SANITIZE_STRING);}
?>
<form method="post" action="">
<input type="text" name="value">
<input type="submit">
</form>
</body>
</html>
First check if form posted.
Related
So the goal is to take the input from a form append it to the end of the URL and then return the HTML from that page.
I am not entirely sure how to take the forms value (in this case $2) and attach it to the URL.
<html>
<head>
<title>Metar Test</title>
</head>
<body>
<form action="" method="POST">
<p>IACO Code: <input type="text" name="$2" value=""></p>
<input type="submit" name="submit" value="Submit">
</form>
<?php $html=file_get_contents("http://www.metar.mysite.net/metar?id=$2")?>
<?php echo $_POST ["$html"];?>
</body>
</html>
On submit any input from a form with method="POST" will be stored in the $_POST global. You can access it from there and append it to your URL string.
<html>
<head>
<title>Metar Test</title>
</head>
<body>
<form action="" method="POST">
<p>IACO Code: <input type="text" name="iacoCode" value=""></p>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if (isset($_POST["iacoCode"])) {
$html = file_get_contents("http://www.metar.mysite.net/metar?id=" . $_POST["iacoCode"]);
echo $html;
}
?>
</body>
</html>
Using the IF statement to check if it is set will prevent it from loading the URL with no variable.
The way we extract data via php from a form is like below
<html>
<head>
<title>Metar Test</title>
</head>
<body>
<form action="" method="POST">
<p>IACO Code: <input type="text" name="$2" value=""></p>
<input type="submit" name="submit" value="Submit">
</form>
<?php $html=file_get_contents("http://www.metar.mysite.net/metar?id=$_POST['$2']")?>
<?php echo $_POST ["$html"];?>
I have following code and it doesn't works for me.
I need print variable from input.
<html>
<head></head>
<body>
<form action='#' method="post">
<input type="text" name="name">
<input type="submit" name="submit">
</form>
<?php
$name = name
echo $name;
?>
</form>
</body>
</html>
Thanks.
you have to use POST to get text from input.
This is right code:
<html>
<head></head>
<body>
<form action='#' method="post">
<input type="text" name="name">
<input type="submit" name="submit">
</form>
<?php
if (isset($_POST['submit']))
{
$name = $_POST['name'];
echo $name;
}
?>
</form>
</body>
</html>
I have two form with submit button in php file
when click on first submit button url become
http://url.com/?valueI=Want
when click second submit button: I need url become http://url.com/
without parameter
How i can do this please
<?php
if (isset($_POST['ASK_Button'])) {
}
if (isset($_POST['SET_Button'])) {
}
?>
<html>
<body>
<form id="ASKUser" class="blocks" action="#" method="post">
<input type="submit" Name="ASK_Button" value="ASK">
</form>
<form id="SETUser" class="blocks" action="#" method="post">
<input type="submit" Name="SET_Button" value="SET">
</form>
</body>
</html>
Change your ask form method to GET
<?php
if (isset($_GET['ASK_Button'])) {
}
if (isset($_POST['SET_Button'])) {
}
?>
<html>
<body>
<form id="ASKUser" class="blocks" action="#" method="GET">
<input type="text" name="valuel" value="Want">
<input type="submit" Name="ASK_Button" value="ASK">
</form>
<form id="SETUser" class="blocks" action="#" method="post">
<input type="submit" Name="SET_Button" value="SET">
</form>
</body>
</html>
With use of action attribute. Set it how you need. Or change it in onSubmit form handler.
I'm trying to upload files to my server but it doesn't work at all. Here is test code:
<?php
echo count($_FILES['upload']['name']);
?>
<!DOCTYPE html>
<html>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<input name="upload[]" type="file" accept=".mp3" multiple="multiple" />
<br>
<input type="submit" value="Upload">
</form>
</body>
</html>
It always prints 0, file upload is enabled on my server.
The problem is that you're not counting the $_FILES['upload'].
Simple fix for your problem
Use:
echo count($_FILES['upload']);
Instead of:
echo count($_FILES['upload']['name']);
Edit:
Remove [] from the input's name.
<?php
echo count($_FILES['upload']);//only this modified//
?>
<!DOCTYPE html>
<html>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<input name="upload[]" type="file" accept=".mp3" multiple="multiple" />
<br>
<input type="submit" value="Upload">
</form>
</body>
</html>
index.php
<html>
<head>
<script type="text/javascript">
function submitForms()
{
document.forms["form-1"].submit();
document.forms["form-2"].submit();
}
</script>
</head>
<body>
<form method="POST" action="form.php" id='form-1'>
<input type="text" name="txt1" />
</form>
<form method="POST" action="form.php" id='form-2'>
<input type="text" name="txt2" />
</form>
<input type="button" value="Click Me!" onclick="submitForms();" />
</body>
</html>
form.php
<?php
echo $_POST['txt1'];
echo $_POST['txt2'];
?>
Above is my code and when i submit both forms then both text-fields with their value it does not shoe me both text-field values.It only shoe me second text-field value.Please help me quickly.
I think because you try to get the params after sumbit two forms. You have sent the two forms at once and the second has stepped to the first, so the result is the return of the second form.
I think this will be better:
<html>
<head>
</head>
<body>
<form method="POST" action="form.php">
<input type="text" name="txt1" />
<input type="text" name="txt2" />
<input type="submit" value="Click Me!" />
</form>
</body>
</html>
<?php
echo $_POST['txt1'];
echo $_POST['txt2'];
?>
Sorry for my english