Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 months ago.
Improve this question
I am trying to make a registration page for my website but when I run it; it gives error. What am I doing wrong?
<?php
//Form values
$name_value=$_POST['Name_input'];
$Username_value=$_POST['Username_input'];
$DOB_value=$_POST['DOB_input'];
$Password_value=$_POST['Password_input'];
$Phone_number_value=$_POST['Phone_number_input'];
$Python_checkbox_value=$_POST['Python_checkbox'];
$Java_checkbox_value=$_POST['Java_checkbox'];
$C_sharp_checkbox_value=$_POST['C#_checkbox'];
$HTML_checkbox_value=$_POST['HTML_checkbox'];
$Cpp_checkbox_value=$_POST['C++_checkbox'];
$R_checkbox_value=$_POST['R_checkbox'];
$swift_checkbox_value=$_POST['swift_checkbox'];
$kotlin_checkbox_value=$_POST['kotlin_checkbox'];
$JS_checkbox_value=$_POST['JS_checkbox'];
Take a look at this code :
<form method="GET">
<input type="checkbox" value="value" name="name">checkbox label</input>
<input type="submit">
</form>
<?php
if (isset($_GET["name"]))
{
echo $_GET["name"];
}
?>
As you can see when I submit the form without checking, the parameter in URI is empty because the checkbox isn't defined (I used GET method)
But when I check it, you can see the parameter is name=value
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have this created a page with numbers and textbox in top of it as you see in the picture
The element id of the textbox is t1
the question is , what's the code I should write on click event to make the numbers written on the textbox .
For example , when I click (1) three times , the textbox should have the value of ( 111 )
any advices ?
JavaScript:
function display(val)
{
document.getElementById("t1").value+=val
}
HTML:
<input type="button" value="1" onclick="display('1')"/>
<input type="button" value="2" onclick="display('2')"/>
<input type="button" value="3" onclick="display('3')"/>
And so on..
display() will call the function to display the value what has been clicked.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
For my project I need to create a simple search engine for my webpage.
I need a way to clear my previous search results when I submit another search into the form without refreshing the entire page.
My Javascript file contains the objects I am searching for.
HTML:
<form>
<div class="form-group">
<input id="term" class="form-control" type="text">
</div>
<button id="search-button" class="btn btn-default" type="button">
Search</button>
</form>
<div id="results-area"></div>
Correct me if i'm wrong:
Code with jQuery:
$(form).submit(function(e){
$("#results-area").html("");
})
Using jQuery it would go like this:
$("#search-button").click(function(){
// your search function here
$("#term).val('');
});
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am wanting to literally take the HTML form input with the ID "bet" and after the value has been entered and submitted; get the exact input for example: '100' may be entered, as I am wanting to perform an if statement to check that the value submitted isn't less than 0 for obvious reasons so then I can stop the webpage proceeding to perform the bet, and make the user instead enter a valid amount.
The code that I am having an issue with is below, upon loading the page I am getting the error: Notice: Undefined index: bet
<form action="duel.php" name="duel" id="duel">
<input type="text" id="betamount" name="betamount">
<?php
$data = $_GET['betamount'];
echo $data;
?>
</form>
I am fairly new to programming in PHP, so any help would be greatly appreciated.
You need to assign a name to the input element. In your situation, you could use the same name as your id:
<input id='bet' name='bet' type='text' value='100' />
To get the specific data for the 'bet' input field use:
echo $_POST['bet'];
On your server to view all of the post data use the code:
// Wrapping the output in the pre block makes the POST data easier to read
echo '<pre>';
print_r($_POST);
echo '</pre>';
This is an example script you can use:
php file:
<?php
if(isset($_POST['submit'];)) {
session_start();
$text = $_POST['Text'];
echo "$text";}else {echo 'Could not load text!';}
?>
<form method="POST">
<input name="Text" type="text">
<input type="submit" name="submit">
</form
So, you would make your form method "POST' and the action the url of the PHP script.
Then, in the PHP script you would use $_POST variable which would contain all of the info that was submitted in that form. See here:
http://php.net/manual/en/reserved.variables.post.php
There is a similar variable for get requests. For hte difference in get and post methods see here:
http://www.w3schools.com/tags/ref_httpmethods.asp
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm having difficulty... I'm trying to create a form which automatically create extra input like .php after the form is submitted.
<form>
<input type="text" name="add" placeholder="Write Test">
<br/>
<input type="submit" name="submit" value="Send">
</form>
When user enters "Test" and press on submit, an automatically extension will be created like this:
Test.php
Thanks in advance.
This can be achieved like this:
<?php
if(!empty($_POST["add"])) {
$file = $_POST["add"] . ".php";
if(file_exists($file)) {
echo "File already exists";
} else {
fopen($file, "w");
}
}
?>
References:
Check if file is already there: http://php.net/manual/en/function.file-exists.php
Create a file / directory : http://php.net/manual/en/function.fopen.php
Concat a string:
$string = $_POST['add'];
$new_string = $string.'.php';
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
<form name="home" action="" onsubmit="return Validateform();" method="post">
<input type="text" name="receiver" />
<input type="submit" value="send" name="send" />
</form>
What is the javascript to alert if the textbox does not start with 92 on submit?
I recommend you read a JavaScript tutorial. Try here.
To answer your question, this will probably work. If you're wondering why you're getting downvoted - asking people to write your code for you is generally considered bad form, so try not to do this in future. :)
function Validateform(e) {
if (document.getElementsByName('receiver')[0].value.substring(0, 2) !== "92") {
e.preventDefault();
alert("Alert");
}
}