Page 1 of 1

If statement from form mail using isset not working.

Posted: Wed Oct 21, 2009 11:30 am
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>";
     }
?>
 
:

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

Posted: Wed Oct 21, 2009 12:11 pm
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.

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

Posted: Wed Oct 21, 2009 12:11 pm
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.

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

Posted: Wed Oct 21, 2009 12:12 pm
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.

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

Posted: Wed Oct 21, 2009 12:13 pm
by markusn00b
Whoopsie daisy. Didn't mean to do that!

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

Posted: Wed Oct 21, 2009 12:15 pm
by Richard Lane
Thank you kindly Mark,

Worked like a charm.

Cheers!

Richard.

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

Posted: Wed Oct 21, 2009 12:47 pm
by markusn00b
Richard Lane wrote:Thank you kindly Mark,

Worked like a charm.

Cheers!

Richard.
You're welcome, Richard.

Take care,
Mark.