DannnnB
DannnnB

Reputation: 5

Form php not working

I have gone searched the net and tried many ways of creating and validating a form which sends info to an email but I can't get my head around it. This is what I have done and it seems to work (have not been able to test if it sends), but every time I submit it comes up with "all fields required error" even with all boxes filled/empty. I looked on this site through similar questions and tried to fix it by them but no luck.

What am I missing? Should I use the php on another page? Once the error is fixed, will it send and keep the information submitted by the user?

In case it helps - I'm using foundation 5 for the site. Beginner at PHP.

<?php
$action=$_REQUEST['action'];
if ($action=="") 
{
?>  
<form action="" method="post">
<div class="row">
<div class="large-12 columns">
<input type="hidden" name="action" value="submit">
<label>Name
<input name"name" type="text" placeholder="Your name"/>
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label>Email
<input name"email" type="text" placeholder="Your email" />
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label>Your Message
<textarea name="message" type="text" placeholder="Comment here"/></textarea>
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<input id="submit"  type="submit" value="Send Message">
</div>
</div>
</form>
<?php
} 
else                
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$message=$_REQUEST['message'];
if (($name=="")||($email=="")||($message==""))
{
echo "All fields required! Please fill <a href=\"\">in the form</a> again.";
}
else{        
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Hire";
mail("myemail", $subject, $message, $from);
// back to homepage - will add send confirm when fixed. header( "Location: ");
}
}  
?>

Thanks in advance for any help!

Upvotes: 0

Views: 64

Answers (3)

BKM
BKM

Reputation: 7079

You are giving input attribute name for name and email like this :

 <input name"name" type="text" placeholder="Your name"/> 
<input name"email" type="text" placeholder="Your email" />

Change it to

 <input name="name" type="text" placeholder="Your name"/> 
<input name="email" type="text" placeholder="Your email" />

Upvotes: 1

Felix
Felix

Reputation: 38102

You're missing = to assign value for your name attribute:

<input name="name" type="text" placeholder="Your name"/>
<!-------  ^ here

and:

<input name="email" type="text" placeholder="Your email" />
<!-------- ^ and here

Upvotes: 2

codelover
codelover

Reputation: 317

check this ..Add= to email and name

 <input name="name" type="text" placeholder="Your name"/>
    </label>
    </div>
    </div>
    <div class="row">
    <div class="large-12 columns">
    <label>Email
    <input name="email" type="text" placeholder="Your email" />
    </label>

Upvotes: 0

Related Questions