If statement from form mail using isset not working.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Richard Lane
Forum Newbie
Posts: 2
Joined: Wed Oct 21, 2009 11:14 am

If statement from form mail using isset not working.

Post by Richard Lane »

Hi there,
I am trying to create some code that sends an email from a form using php. If the email field is not filled out, I don't want the script to send the form. I am trying to do that using isset. The problem is that the php script (which is in a separate file, goes ahead and sends the mail whether or not the email field is filled out. In other words the email field seems to be always filled out even when it's not. Would anyone please help me to understand what is going wrong? Thank you!

Here is the code for the form on the first page which is called Contact.html:

Code: Select all

 
<div id="ContactText">
     <form method="post" action="ContactSend.php">
     <table width="300" border="0">
          <tr>
               <td align="right" valign="top"><p class="contactFormText">Name:</p></td>
               <td class="contactFormText"><input type="text" name="fullname" id="tswname" /></td>
          </tr>
          <tr>
               <td align="right" valign="top"><p class="contactFormText">Email:</td>
               <td><input type="text" name="email" id="tsemail" /></td>
           </tr>
           <tr>
                <td align="right" valign="top"><p class="contactFormText">Message:</td>
                <td><textarea name="comments" id="tswcomments" cols="45" rows="5"></textarea></td>
           </tr>
           <tr>
                <td align="right" valign="top">&nbsp;</td>
                <td><input type="submit" name="SubmitButton" id="SubmitButton" value="Send" /></td>
           </tr>
     </table>
</form>
</div>
 
And here is the code for the php script called ContactSend.php

Code: Select all

 
<?php
     // if email field is filled out, send email. NOTE: This is the thing that doesn't work!
     if (isset($_REQUEST['email']))
     {
          $Full_Name = $_REQUEST["fullname"];
          $Email = $_REQUEST["email"];
                                
          $Comments = $_REQUEST["comments"];
                                                                
          $Body = "$Full_Name\r\n$Email\r\n$Comments";
                                
          mail("jherman@legendanimation.com", "Message from website", $Body, "From $Full_Name:");
                                
          echo "<p class='description'>Your message has been sent.</p>";
          echo "<p class='description'>Thank you for contacting us.</p>";
     }
     else
     // If email field is not filled out
     {
          echo "<p class='description'>A mail error has occurred.</p>";
          echo "<p class='whatever'><a href='Contact.html'>Click here to try again</a>";
     }
?>
 
:
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: If statement from form mail using isset not working.

Post by markusn00b »

Even if the field is empty, it is still sent as part of the form.

Check that there is some data in the 'email' index.

Code: Select all

 
if (isset($_POST['email']) && $_POST['email'] != '')
 
Mark.

P.S. Don't use REQUEST if you *know* that you're using POST.
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: If statement from form mail using isset not working.

Post by markusn00b »

Even if the field is empty, it is still sent as part of the form.

Check that there is some data in the 'email' index.

Code: Select all

 
if (isset($_POST['email']) && $_POST['email'] != '')
 
Mark.

P.S. Don't use REQUEST if you *know* that you're using POST.
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: If statement from form mail using isset not working.

Post by markusn00b »

Even if the field is empty, it is still sent as part of the form.

Check that there is some data in the 'email' index.

Code: Select all

 
if (isset($_POST['email']) && $_POST['email'] != '')
 
Mark.

P.S. Don't use REQUEST if you *know* that you're using POST.
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: If statement from form mail using isset not working.

Post by markusn00b »

Whoopsie daisy. Didn't mean to do that!
Richard Lane
Forum Newbie
Posts: 2
Joined: Wed Oct 21, 2009 11:14 am

Re: If statement from form mail using isset not working.

Post by Richard Lane »

Thank you kindly Mark,

Worked like a charm.

Cheers!

Richard.
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: If statement from form mail using isset not working.

Post by markusn00b »

Richard Lane wrote:Thank you kindly Mark,

Worked like a charm.

Cheers!

Richard.
You're welcome, Richard.

Take care,
Mark.
Post Reply