Recently I got this problem that I cannot solve. My HTML form cannot be submitted by using iPad, but the same form CAN be submitted from my laptop (windows machine). Please check this out:
http://www.gomap.ch/admin/pages/test.php - this is submitted correctly
http://ipadpreview.com/previewer?url=www.gomap.ch/admin/pages/test.php - this is not submitted.
This is a very simple form, and code goes like this:
<?php
error_reporting(0);
if($_POST['mirko']){
echo 'hello, Mirko';
}
?>
<form action="" method="POST">
<input type="submit" value="Submit" name="mirko"/>
</form>
Any help, please??
Thanks a lot!
You are not using valid html.Replace your code with this and have u tried on real ipad.
<html>
<head></head>
<body>
<?php
error_reporting(0);
if($_POST['mirko']){
echo 'hello, Mirko';
}
?>
<form action="" method="POST">
<input type="submit" value="Submit" name="mirko"/>
</form>
</body>
</html>
You need to add the name of the form which holds the php code into the action. In this case it would be the same form you're on. Follow what I did below with nameOfFile.php being the name of the file you posted.
<?php
error_reporting(0);
if($_POST['mirko']){
echo 'hello, Mirko';
}
?>
<form action="nameOfFile.php" method="POST">
<input type="submit" value="Submit" name="mirko"/>
</form>
Related
I really don't know why my code isn't working! Let me clear it by example..
I got a file named 'index.html' example...
<html>
<body>
<form action="test.php" method="post">
Name: <input type="text" name="test">
<input type="submit">
</form>
</body>
</html>
And of course the form action file test.php .. example..
<?php
$something = ($_POST["test"]);
// from here I have some PHP codes and this "something" variable will be process in this codes and will print out something spacial..
?>
Now example If I post "Hello, It's not working" then the output will show a spacial design.
But Instead process, it's just printing out whatever I submit in that form.
But when I manually add the variable to "something" and if I execute the "test.php" . Example..
$something = "Hello, It's not working";
Then it works perfectly..
And yes. Also tried GET method.. It's still same as POST.
This is my first question here..
Thanks for any help and suggestions!
First Convert, index.html to php and follow this code:-
<html>
<body>
<form action="test.php" method="post">
Name: <input type="text" value="" name="test">
<input name="submit" value="submit" type="submit">
</form>
</body>
</html>
<?php
if(isset($_POST['submit'])){
$something = $_POST["test"];
}
?>
That's correct _POST:
<?php
//NO ($_POST["test"])
$something = $_POST["test"];
?>
I have this code:
<!DOCTYPE html>
<html>
<body>
<iframe name="votar" style="display:none;"></iframe>
<form id="excel form" method="post" target="votar">
<input type="submit" name="test" id="test" value="RUN" /><br/>
</form>
</body>
</html>
<?php
if(isset($_POST['test']))
{
echo "hello world";
}
?>
what am I trying to do? well I try to get hte post data from this form without reloading the page and without using ajax, but what am I doing wrong? I tried looking around, but all the other solutions are to long or just not prectical for my website. please help.
EDIT
just changed submit to test, doesn't matter.
<form action="" method="post" >
<!-- code -->
</form>
I updated the question.
Since the last code was pretty complex and even after fixing the stuff it didn't work, I executed the below simple code to check if things work. Even this code doesn't work. Whenever I click on the submit button, it again returns a 404 error.
Yes, I placed the PHP code in the body as well to check if this work but it doesn't.
<?php
if(isset($_POST['submit'])) {
echo("Done!!!!");
} else {
?>
<html>
<head>
<title>Echo results!</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input name="submit" type="submit" value="submit"/>
</form>
<?php
}
?>
</body>
</html>
Try giving the button_create as name of the submit button
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
if(isset($_POST['button_create'])) {
<td><input type="submit" name="button_create" id="button_create" value="Create Table!"></td>
change these lines see how you go from there
There are a couple of things wrong here, method should be POST instead of GET. The name attribute of text fields should be used when receiving the values. The submit button name should be used to check whether the button is clicked or not. See the example given below.
<?php
if (isset($_POST['submit'])) {
$ex1 = $_POST['ex1'];
$ex2 = $_POST['ex2'];
echo $ex1 . " " . $ex2;
}
?>
<form action="" method="post">
Ex1 value: <input name="ex1" type="text" />
Ex2 value: <input name="ex2" type="text" />
<input name="submit" type="submit" />
</form>
Echo results!
<?php
if(isset($_POST['submit'])) {
echo("Done!!!!");
} else {
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input name="submit" type="submit" value="submit"/>
</form>
<?php
}
?>
this is for your updated question
I have been trying to create a form that reads a post from an HTML form and displays an element from that post IF it detects that the post exists.
However, each time the post is submitted, it simply reloads the form as though no post were provided.
<!DOCTYPE html>
<html>
<head>
<title>Upload from Manifest</title>
</head>
<body>
<?php
if (isset($_POST['manifest'])) {
echo 'we are in the IF';
echo($_POST['manifest']);
}
?>
<h1>Submission from manifest into main db</h1>
<div class="container offset-top120">
<form method="post" action="https://nhsggc.cogiva.com/prism/loadFromManifest.php" enctype="multipart/form-data">
<input id="manifest" type="text" />
<input id="submit" value="Submit" type = "submit" />
</form>
</div>
</body>
</html>
Your form is going to either a different page (https://nhsggc.cogiva.com/prism/loadFromManifest.php so check for that first) if you wanted it to go to same page, you can give the action as just '#', or put in the whole URL like you have.
You're missing the name attribute from your submit input and text input. Read up on the name attribute!
<input id="manifest" type="text" name="manifest">
<input id="submit" value="Submit" type="submit" name='submit' />
Then your PHP should look like this:
<?php
if (isset($_POST['submit'])) {
echo 'Inside an if';
echo $_POST['manifest'];
}
Then it should work.
I was trying to call a particular php function in submit of a form both the form and php scripts are in same page. My code is below.(it is not working and so I need help)
<html>
<body>
<form method="post" action="display()">
<input type="text" name="studentname">
<input type="submit" value="click">
</form>
<?php
function display()
{
echo "hello".$_POST["studentname"];
}
?>
</body>
</html>
In the following line
<form method="post" action="display()">
the action should be the name of your script and you should call the function, Something like this
<form method="post" action="yourFileName.php">
<input type="text" name="studentname">
<input type="submit" value="click" name="submit"> <!-- assign a name for the button -->
</form>
<?php
function display()
{
echo "hello ".$_POST["studentname"];
}
if(isset($_POST['submit']))
{
display();
}
?>
you don't need this code
<?php
function display()
{
echo "hello".$_POST["studentname"];
}
?>
Instead, you can check whether the form is submitted by checking the post variables using isset.
here goes the code
if(isset($_POST)){
echo "hello ".$_POST['studentname'];
}
click here for the php manual for isset
Assuming that your script is named x.php, try this
<?php
function display($s) {
echo $s;
}
?>
<html>
<body>
<form method="post" action="x.php">
<input type="text" name="studentname">
<input type="submit" value="click">
</form>
<?php
if($_SERVER['REQUEST_METHOD']=='POST')
{
display();
}
?>
</body>
</html>
PHP is run on a server, Your browser is a client. Once the server sends all the info to the client, nothing can be done on the server until another request is made.
To make another request without refreshing the page you are going to have to look into ajax. Look into jQuery as it makes ajax requests easy
If you want to call a function on clicking of submit button then you have
to use ajax or jquery,if you want to call your php function after submission of form
you can do that as :
<html>
<body>
<form method="post" action="display()">
<input type="text" name="studentname">
<input type="submit" value="click">
</form>
<?php
function display()
{
echo "hello".$_POST["studentname"];
}
if($_SERVER['REQUEST_METHOD']=='POST')
{
display();
}
?>
</body>
</html>
Write this code
<?php
if(isset($_POST['submit'])){
echo 'Hello World';
}
?>
<html>
<body>
<form method="post">
<input type="text" name="studentname">
<input type="submit" name="submit" value="click">
</form>
</body>
</html>
An alternative, and perhaps a not so good procedural coding one, is to send the "function name" to a script that then executes the function. For instance, with a login form, there is typically the login, forgotusername, forgotpassword, signin activities that are presented on the form as buttons or anchors. All of these can be directed to/as, say,
weblogin.php?function=login
weblogin.php?function=forgotusername
weblogin.php?function=forgotpassword
weblogin.php?function=signin
And then a switch statement on the receiving page does any prep work and then dispatches or runs the (next) specified function.