HTML form PHP post not working - php

I'm writing a little website for myself and I'm having trouble with what seems like a simple line of code:
form action="send.php" method="post"
Furthermore, even a simple line like form action="http://www.google.com"> isn't working. Here is my code:
<html>
<head>
<title>
AnonMail!
</title>
</head>
<body style="font-family:'Tahoma';>
<form action="send.php" method="post">
<label for="from">From: </label><input type="text" name="from" id="from"></input></br>
<label for="to">To: </label><input type="text" name="to" id="to"></input></br>
<label for="subj">Subject: </label><input type="text" name="subj" id="subj"></input></br>
<textarea rows=10 cols=100 name="message"></textarea></br>
<input type="submit" value="Send"/>
</form>
</body>
</html>

The error starts with your body tag.
You have not closed your double quotes in the style tag of your body.
Just close it properly and then run it.
I think that is only the problem.

Here's a form that should work:
<html>
<body>
<form action="contact.php" method="post">
<p><b>Your Name:</b> <input type="text" name="yourname" /><br />
<b>Subject:</b> <input type="text" name="subject" /><br />
<b>E-mail:</b> <input type="text" name="email" /><br />
Website: <input type="text" name="website"></p>
<p><input type="submit" value="Send it!"></p>
</form>
</body>
</html>
If you're still having troubles: http://myphpform.com/php-form-not-working.php

browsers show warnings when your action refers to an external source. Some browsers do not post form at all. This is unsafe for users.

Related

Data entered in index.php cannot show on process.php

Was trying to follow a tuitorial online on how to submit data using html to mysql database.
I created 2 php files named index.php and process.php. What i wanted to show was what I typed in inside index.php will show on process.php when I clicked on the button "add employee". But nothing showed up.
Here is what's inside index.php
<!DOCTYPE html>
<html>
<head>
<style>
label{display:inline-block;width:100px;margin-bottom:10px;}
</style>
<title>Add Employee</title>
</head>
<body>
<form method="post" action="">
<label>First Name</label>
<input type="text" name="first_name" />
<br />
<label>Last Name</label>
<input type="text" name="last_name" />
<br />
<label>Department</label>
<input type="text" name="department" />
<br />
<label>Email</label>
<input type="text" name="email" />
<br />
<input type="submit" value="Add Employee">
</form>
</body>
</html>
Here is a Screenshot of the form.
click here for index.php image
Wile here is what's inside the process.php
<?php
print_r($_POST);
This is what shows up
process.php image
Sorry a beginner at this. Hope you guys can help. Thank you!
Maybe you are missing the "action"?
<form method="post" action="/process.php">
You should specify what you need.Somethings like this:
<?php
print_r($_POST['first_name']);
Or use foreach loop to get full array value.
You can go through with fill up action tag so when you submit the form it will go to proccess.php page.
<form method="post" action="process.php">

why my forms are not working in bootstrap website?

I tried all but no form is working with method or simple action like http://google.com `
<form action="http://google.com" method="post">
<input type="text" />
<input type="submit" />
</form>
even this is not working
use this
<form role="form" action="http://google.com" method="post">
<input type="text" name="text" />
<input type="submit" name="submit" />
</form>
role attribute for FORM
name attribute for input
In PHP, $_POST always accept name attribute from form elements:-
You need to write
<input type="text" name='name_of_your_field' />
instead of
<input type="text" />
You need to refer this Link.

Ckeditor data not retrieved for some form (php)

I made a post here a couple of days ago :
Ckeditor content retrieval using PHP
(I hope this is ok, by the way, asking a related question in a new thread, but it seemed awkward to stay on the same thread).
It's now working fine. However, when replacing textareas by ckeditor in other forms, the data isn't retrieved although the code is very similar.
I think I might be limited by my understading of php forms for this problem. Anyway, here's the code :
<section id="mainsection">
<script src="http://localhost/Project/ckeditor/ckeditor.js"></script>
<h1> ADD INDIVIDUAL </h1>
<form enctype="multipart/form-data" action=<?php echo $_SERVER['PHP_SELF']?> method="post">
<p>
<label for="fullname">Full Name</label> : <input type="text" name="fullname" id="fullname" /><br />
<label for="description">Biography</label> : <input type="textarea" name="description" id="description" /><br />
<label for="file">Find image</label> : <input name="personimage" type="file" id="personimage" /><br />
<input type="submit" value="Envoyer" />
</p>
<script>
CKEDITOR.replace( 'description' );
</script>
<script type="text/javascript" src="http://localhost/Project/js/update.js"></script>
</form>
<?php
var_dump($_POST);
/* if(isset($_POST['fullname']) AND isset($_POST['description']))
{
$post = array('fullname' => $_POST["fullname"],
'description' => $_POST["description"],
);
add_person($post);
}else{
echo 'Not every parameter has been set';
}*/
?>
The code works fine without ckeditor. But the present code doesn't add the ckeditor content to $_POST, which confuses me as it doesn't seem to be fundamentally different to the code in the link I posted.
There are some validation errors which should be fixed
So firstly, action's value <?php echo $_SERVER['PHP_SELF']?> should be closed with quotes (""), but there is no need to fill this attribute with $_SERVER['PHP_SELF']. You may let this attribute empty.
After that, you should use <textarea></textarea> format what is more valid than <input type="textarea" /> as you can see in W3 Input reference there is no input type=textarea option. So it should be
<textarea name="description" id="description"></textarea>
Instead of
<input type="textarea" name="description" id="description" />
The final result should looks like this:
<form enctype="multipart/form-data" action="" method="post">
<p>
<label for="fullname">Full Name</label> : <input type="text" name="fullname" id="fullname" /><br />
<label for="description">Biography</label> : <textarea name="description" id="description"></textarea><br />
<label for="file">Find image</label> : <input name="personimage" type="file" id="personimage" /><br />
<input type="submit" value="Envoyer" />
</p>
<script>
CKEDITOR.replace( 'description' );
</script>
<script type="text/javascript" src="http://localhost/Project/js/update.js"></script>
</form>
After these changes, try var_dump($_POST); again.

trying to post to php file - server error

I'm a newbie here to php and Apache.
I have an html form:
<html>
<body>
<?php
<form method="post" action="contact.php"> Email: <input name="email"
type="text"/><br/> Message:<br/> <textarea name="message" rows="15" cols="40">
</textarea><br/> <input type="submit"/> </form>
</body>
</html>
I have contact.php located in what I believe is the right place, but when I submit the query, I get "The HTTP verb POST used to access path '/www/contact.php' is not allowed."
When I access contact.php as a url I get strange results (like a repeating File Download message box asking whether I want to Save or Open)
if you are using which is missing in your code.
for your below code will work.
<html>
<body>
<form method="post" action="contact.php"> Email: <input name="email"
type="text"/><br/> Message:<br/> <textarea name="message" rows="15" cols="40">
</textarea><br/> <input type="submit"/> </form>
</body>
</html>
First Thing Give Name to Submit Button and second remove
<html>
<body>
<form method="post" action="contact.php"> Email: <input name="email"
type="text"/><br/> Message:<br/> <textarea name="message" rows="15" cols="40">
</textarea><br/> <input type="submit" name="submit" /> </form>
</body>
</html>
and if you can still face an error then try to give full file path in action

PHP/HTML form submission

I have the HTML and PHP code
<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name<form method="post">
<input name="servername" type="text" /></form>
<p>Description<form method="post">
<input name="description" type="text" /></form>
<p>Server IP<form method="post">
<input name="ip" type="text" /></form>
<p>Tags (ex: "pvp, economy, fun")<form method="post">
<input name="tags" type="text" /></form>
<form method="post">
<input name="submitserver" type="submit" value="submit" /></form>
</p>
and
(addaserver.php)
$servername=$_POST['servername'];
$desc=$_POST['description'];
$ip=$_POST['ip'];
$tags=$_POST['tags'];
Obviously I'm trying to get the data from the forms...however when I click "submit" it just reloads the page the forms are on. It's probably just some simple error, but I can't figure out what's wrong D:
You're supposed to define only one form, not one for each input:
<form name="addaserver" method="post" action="addaserver.php">
inputs, inputs, inputs, submit
</form>
First thing I see wrong is that you have two separate form tags in the same HTML.
The second one is pretty much useless as it provides no data to any target or action. I would restructure your HTML to be more like this and try it;
<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name<form method="post">
<input name="servername" type="text" /></p>
<p>Description<form method="post">
<input name="description" type="text" /></p>
<p>Server IP<form method="post">
<input name="ip" type="text" /></p>
<p>Tags (ex: "pvp, economy, fun")
<input name="tags" type="text" /></p>
<p><input name="submitserver" type="submit" value="submit" /></p>
</form>
Also take note of the fact that I got rid of all your closing form tags as they would have caused issues too. You only need one closing tag at the very outside most segment of your form's body as shown in the code sample too.
You have way too many <form method="post"> tags in your code.
Your code should start with <form method="post"> and end with </form>, but in between there should only be input fields.
You define action to 'addaserver.php' in the first <form> tag, but the submission button is after a different <form> tag so it doesn't respect that initial target you are setting.
You seem to be enclosing all your input element in different tags. a Form tag is a collection of Form elements that will have their values submitted when the form is submitted. And if you do not specify the action attribute on a form it will (as you say) reload the page. So in the above example if you remove all the tags surrounding the input tags and put them all under the same tag you should get your information posted
Look at http://www.w3schools.com/html/html_forms.asp and http://www.tizag.com/phpT/examples/formex.php for examples on how to do this.
Hope that makes sense.
You only need one form tag for the whole form to submit
<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name
<input name="servername" type="text" /></p>
<p>Description
<input name="description" type="text" /></p>
<p>Server IP<form method="post">
<input name="ip" type="text" /></p>
<p>Tags (ex: "pvp, economy, fun")
<input name="tags" type="text" />
<input name="submitserver" type="submit" value="submit" /></form>
</p>
You're nesting extra form tags throughout your form. You only need one form tag. All of the inputs go inside it.
<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name</p>
<input name="servername" type="text" />
<p>Description<</p>
<input name="description" type="text" />
<p>Server IP</p>
<input name="ip" type="text" />
<p>Tags (ex: "pvp, economy, fun")</p>
<input name="tags" type="text" />
<input name="submitserver" type="submit" value="submit" />
</form>
Try this instead:
<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name: <input name="servername" type="text" /></p>
<p>Description: <input name="description" type="text" /></p>
<p>Server IP: <input name="ip" type="text" /></p>
<p>Tags (ex: "pvp, economy, fun")<input name="tags" type="text" /></p>
<p><input name="submitserver" type="submit" value="submit" /></p>
</form>

Categories