Jump to content


Photo

Form Emailer -- Stop Process


  • Please log in to reply
6 replies to this topic

#1 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 18 August 2006 - 05:40 PM

I currently have an emailer which emails fine without a problem

but when you click submit it submits even though they didnt fill out some fields
can someone please help

<?php

if(isset($_POST['Submit'])){

$to = "$email";
$subject = "$idea";
$from_header = "From: $from";

   mail($to, $subject, $contents, $from_header);

echo "Thank You for using the 2fr3sh emailer the messages have been sent!";}else{ ?>


<div align="center">
<form action="" method="post">
          <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="padding-left:10px;">
		
            <tr> 
              
      <td height="53"> 
        <div align="left"><font color="black">Subject:</font><font color="#000000"><br>
                  </font> 
                  <input name="idea" type="text" id="idea" size="50">
                  <br>
                </div></td>
				
            </tr>
					
            <tr> 
              
      <td height="51"> 
        <div align="left"><font color="black">To Email Address:</font><br>
                  <input name="email" type="text" id="email" size="50">
                  <br>
                </div></td>
            </tr>
            <tr> 
              
      <td height="50"> 
        <div align="left"><font color="black">From Email Address:</font><br>
                  <input name="from" type="text" id="from" size="50">
                  <br>
                </div></td>
            </tr>


            <tr> 
              <td> <div align="left"><font color="black">Message:</font><br>
                  <textarea name="contents" cols="44" rows="5" id="contents"></textarea>
                </div></td>
            </tr>







            <tr> 
              <td><div align="center"> <br>
                  <input type="Submit" value="Send Email" name="Submit">
                  <input type="reset" value="Reset Form">
                </div></td>
            </tr>
          </table>
        </form></div>

<?php
};

?>
???

#2 Ifa

Ifa
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationRauma, Finland

Posted 18 August 2006 - 05:48 PM

You have to make a similar check for all the fields as you have done for the submit:
if(isset($_POST['Submit']))
I'm just a guy who likes to code for fun...

#3 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 18 August 2006 - 05:51 PM

Add another check on one of the other fields

if(isset($_POST['Submit']) && isset($_POST['email'])){

Ray

#4 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 18 August 2006 - 05:55 PM

so it would look something like this
if(isset($_POST['Submit']) && isset($_POST['email']) && isset($_POST['from']) && isset($_POST['contents'])){

because it still doesnt work

#5 Woolf

Woolf
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 18 August 2006 - 08:52 PM

Perhaps you should try something like this:

<?php

if(!empty($_POST['idea']) && !empty($_POST['email']) && !empty($_POST['contents']) && isset($_POST['Submit'])){

$to = "$email";
$subject = "$idea";
$from_header = "From: $from";

   mail($to, $subject, $contents, $from_header);

echo "Thank You for using the 2fr3sh emailer the messages have been sent!";}else{ ?>

In theory, that should work.

#6 Ifa

Ifa
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationRauma, Finland

Posted 20 August 2006 - 09:52 PM

!empty is kinda the same as isset...
I'm just a guy who likes to code for fun...

#7 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 21 August 2006 - 12:34 AM

you shoudl use isset because it is much more flexible when changing scripts.... perez nearly go it right...

You can use isset for all the variables you need like so...

<?php

if (
   isset(
         $_POST['email'],
         $_POST['from'],
         $_POST['contents']
         )
   )
{


....

?>

Now as you can see if you need to add another variable that must be filled in it is mereley a case of adding the new var to the list in the isset construct.

$_POST['email']) && isset($_POST['from']) && isset($_POST['contents'
follow me on twitter @PHPsycho




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users