I keep getting "Undefined index: latitude" and "Undefined index: longitude"
I was trying to make it work for hours, but i am not able to :( Would you please help me?
I need those two forms seperated each other.How can i link them together?
Thanks in advance :)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title</title>
</head>
<script>
var x=document.getElementById("log");
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{x.innerHTML="GPS szolgáltatás nem müködik ezen a böngészőn, kérlek értesítsd a rendszergazdát!";}
}
function showPosition(position)
{
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
document.getElementById("longitude").value = longitude;
document.getElementById("latitude").value = latitude;
}
</script>
<p id="log">
<form method="post">
<input type="hidden" name= "longitude" id="longitude">
<input type= "hidden" name ="latitude" id="latitude">
</form>
</p>
<br>
<br>
<form action="" method="post">
<input type="submit" name="ido" value="Click" /></td>
</form>
<?php
if(isset($_POST["ido"])) {
echo "<script>getLocation();</script>";
$latitude=$_POST["latitude"];
$longitude=$_POST["longitude"];
print_r($_POST);
}
?>
</html>
That is because your form does not contain the elements latitude and longitude , whereas the above form what you have defined has those fields , but they are never submitted.
<form action="" method="post">
<input type="hidden" name= "longitude" id="longitude"> <!-- I have added here-->
<input type= "hidden" name ="latitude" id="latitude"> <!-- I have added here-->
<input type="submit" name="ido" value="Click" /></td>
</form>
If you need the forms to be independent - then you should consider using a custom submit method and submit via ajax. That will give you the opportunity to parse the elements you need and then submit the data.
Related
im currently trying to get a value from a textbox but im always getting undefined array key.
<head>
<!-- Links -->
<link rel="stylesheet" href="./css/vouches.css">
</head>
<body>
<div class="content">
<form method="get"><input type="text" id="oderid" name="oderid" placeholder="oderid / invoiceid"></form>
<form method="post"><input type="submit" name="button1"class="submitbtn" value="Button1" /></form>
<?php
if(array_key_exists('button1', $_POST)) {
button1();
}
function button1() {
$id = $_GET['orderid'];
echo $id;
}
?>
</div>
</body>
</html>
in the part is where the stuff happens. I hope i can get some help, im really new to php
When clicking the button it should echo $id, better said the textbox input
Don't use both POST and GET; pick one.. Like this:
<form method="post">
<input type="text" id="oderid" name="orderid" placeholder="oderid / invoiceid" />
<input type="submit" name="button1" class="submitbtn" value="Button1" />
</form>
<?php
if(array_key_exists('button1', $_POST)) {
button1();
}
function button1() {
$id = $_POST['orderid'];
echo $id;
}
?>
Also take care of your spelling, orderid is not the same as oderid.
Hello if an input which is inside a form and other input which is outside form , I can set a varible of that input which is inside form , but how Can I make a varible of that input which is outside ?
just like I have an input which name is name and it is inside form and i have another input which name is type when I click on submit button it is showing an error
Notice: Undefined index: type in B:\xampp\htdocs\gst3\front\test99.php on line 4
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$type=$_POST['type'];
echo "ok";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>test09</title>
</head>
<body>
<input type="text" placeholder="type" name="type" >
<form action="" method="post">
<input type="text" name="name" placeholder="name">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
You need jQuery to get input values outside the form.
I think following will work for you:
$('form').on('submit', function(e){
e.preventDefault();
postData = {};
postData['outerData'] = $("input[name='type']").val();
postData['formData'] = $(this).serialize();
$.post('url', postData);
});
<?php
if(isset($_POST['submit'])){
// Here the code captures the inputs that entered.
Based on the inputs the script shows the associated information.
}
<form method="POST">
<input type="text" name="postc">
<input type="text" name="nr">
<button name="submit">Send</button>
</form>
How to check that both of the inputs are filled and if they are filled automaticly load the PHP code to get the data. (I'm a beginner)
I hope I explained it right!
Example page
http://bit.ly/1hx0EKS
I'd suggest something like below:
HTML
<form method="POST" name="myForm" action="page.php">
<input type="text" name="postc" onchange="submitForm()">
<input type="text" name="nr" onchange="submitForm()">
</form>
Javascript
this function is called anytime you fill an input of your form. It provides to get your input values and submit dynamically the form ONLY when you filled all your (in this case) inputs.
function submitForm() {
var postc = document.forms["myForm"]["postc"].value;
var nr = document.forms["myForm"]["nr"].value;
if (postc != "" && nr != "")
document.myForm.submit();
}
EDIT
This is a full working example
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Your title</title>
<script>
function submitForm() {
var postc = document.forms["myForm"]["postc"].value;
var nr = document.forms["myForm"]["nr"].value;
if (postc != "" && nr != "") {
document.myForm.submit();
}
}
</script>
</head>
<body>
<form method="POST" name="myForm" action="#">
<input type="text" name="postc" onchange="submitForm()">
<input type="text" name="nr" onchange="submitForm()">
</form>
<?php
if(isset($_POST['postc'])){
echo "postc value: " . $_POST['postc'] . '<br />';
echo "nr value: " . $_POST['nr'];
}
?>
</body>
</html>
hope this helps :-)
I just wanna ask how can I make a form with two buttons that do different functions? Like for example: I have this table with checkboxes and when a checkbox was checked and a certain button was clicked, the button will perform its assigned task.
Button1 can add, button2 can delete.
Can you help me again, please? I'm kind of new at this and I really want to know. Thank you!
This is more of a JavaScript question than PHP.
You'll need to add an onclick to your buttons:
<input type="button" onclick="functionA();" value="button a" />
<input type="button" onclick="functionB();" value="button b" />
Then create these functions in JavaScript:
function functionA()
{
// do stuff
alert("add");
}
function functionB()
{
// do stuff
alert("delete");
}
Here's a basic example of where you can stick your JavaScript etc:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<script type="text/javascript">
function functionA()
{
// do stuff
alert("add");
}
function functionB()
{
// do stuff
alert("delete");
}
</script>
</head>
<body>
<input type="button" onclick="functionA();" value="button a" />
<input type="button" onclick="functionB();" value="button b" />
</body>
</html>
If you are looking at a server side solution, you can have two submit buttons in the form with different name attributes and then check the $_GET['buttonName'] or $_POST['buttonName'] variables depending on your form submission method.
For example:
<form action="action.php" method="post">
<input type="text"....blah blah />
....
<input type="submit" name="add" value="Add" />
<input type="submit" name="delete" value="Delete" />
</form>
i make a dynamic textbox through javascript now i want to post the data of all dynamically generated textboxes to php script and then insert into a table.
how can i do this...
<head>
<title>Dynamic Form</title>
<script language="javascript">
function changeIt()
{
var i = 1;
my_div.innerHTML = my_div.innerHTML +"<br><input type='text' name='mytext'+ i>"
}
</script>
</head>
<body>
<form name="form" action="post" method="">
<input type="button" value="add another textbox" onClick="changeIt()">
<div id="my_div">
<input type="submit" value="save">
</body>
HI, whenever you post your form at that time all the fields are posted on the php script, where you can get array of that textbox variable by using for loop.
ex:
$textboxarr = array();
for($i = 0;$i<count($_POST['mytext']);$i++){
$textboxarr = $_POST['mytext'][$i];
}
now you having your all text boxes in the $textboxarr.try this.
Thanks.
Use it like this
<head>
<title>Dynamic Form</title>
<script language="javascript">
function changeIt()
{
my_div.innerHTML = my_div.innerHTML +"<br><input type='text' name='mytext[]'>"
}
</script>
</head>
<body>
<form name="form" action="post" method="">
<input type="button" value="add another textbox" onClick="changeIt()">
<div id="my_div">
<input type="submit" value="save">
</body>
In php you will be able to use it as an array like
$_POST['mytext'][0], $_POST['mytext'][1] etc... or you can use a foreach loop for $_POST['mytext']