Jump to content

Form sending, whether fields filled or not...


Jezthomp

Recommended Posts

Recently i have noticed that a form template i have been using is not checking whether certain fields are not filled in and just posting the form regardless.

 

 

<?php
ini_set("sendmail_from", "mailserver@*******.co.uk");

if ($_POST["formName"] == "contactForm") {

if (($_POST["name"] == "") OR ($_POST["email"] == "") OR ($_POST["telNum"] == "")) {

print "<br>You have not given us all the information we need to process the form.<br>";
print "Please use the browser back and/or refresh button to go back and edit the form.";
}else{

$recipient = "Enquiries <jez@website.net>"; 
$subject = "Website Enquiry Form"; 

$name = $_POST["name"];
$telNum = $_POST["telNum"];
$email = $_POST["email"];
$website = $_POST["website"];
$comments = $_POST["comments"];

$message = "WEBSITE CONTACT FORM:
____________________________________________
Contact Info:

Name: $name

E-Mail Address: $email

Contact No: $telNum

There Website: $website
____________________________________________
Comments:

Comments: $comments


"; 

$extra = "From: $name <$email>"; 

mail ($recipient, $subject, $message, $extra); 


print "Many Thanks $name! for contacting us, we shall get back to you as soon as possible...";
}
} else { ?>
<form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post" name="contactForm">
<fieldset>
<legend>Enquiry Form </legend>
<div class="fieldContact">
<label for="name">Name: <span class="required" title="This field is required.">*</span></label>
<input class="text" id="name" maxlength="64" name="name" size="24" title="Enter name here" value="Enter name here"onfocus="if (this.value == this.defaultValue) this.value = ''" onblur="if (!this.value) this.value=this.defaultValue" type="text"/>
</div>
<div class="fieldContact">
<label for="email">Email Address: <span class="required" title="This field is required.">*</span></label>
<input class="text" id="email" name="email" size="32" title="Enter email address here" value="Enter email address here" onfocus="if (this.value == this.defaultValue) this.value = ''" onblur="if (!this.value) this.value=this.defaultValue"type="text"/>
</div>
<div class="fieldContact">
<label for="telNum">Tel No:<span class="required" title="This field is required.">*</span></label>
<input name="telNum" class="text" id="telNum" title="Enter telephone number here" value="Enter telephone number here"onfocus="if (this.value == this.defaultValue) this.value = ''" onblur="if (!this.value) this.value=this.defaultValue" size="32" type="text"/>
</div>
<div class="fieldContact">
<label for="comments"><span>Comments:</span></label>
<textarea name="comments" cols="25" rows="5" class="text" id="comments"></textarea>
</div>
</fieldset>
<div><input name="Submit" type="submit" class="submit" value="Submit" /><input name="formName" type="hidden" id="formName" value="contactForm" /></div>
</form>
<?php } ?>

 

Is suddenly not working when it used too

 

This is an older form i used and it works in regard to checking the fields, the only difference is the one that doesnt work is a css form.

 

	<?php
				ini_set("sendmail_from", "mailserver@********.net");

if ($_POST["Submit"]) {

	if ((!$_POST["name"]) OR (!$_POST["telNum"]) OR (!$_POST["email"])) {

		print "<br>You have not given us all the information we need to process the form.<br>";
		print "Please use the browser back and/or refresh button to go back and edit the form.";
	}else{

		$recipient = "Enquiries <enquiries@*******.net>"; 
		$subject = "Website Enquiry Form"; 

$name = $_POST["name"];
$company = $_POST["company"];
$telNum = $_POST["telNum"];
$email = $_POST["email"];
$message = $_POST["message"];



$message = "WEBSITE CONTACT FORM:
____________________________________________
PERSONAL INFO:

Name: $name
Company: $company
Contact No: $telNum
E-Mail Address: $email

____________________________________________
MESSAGE:

Message: $message


"; 

		$extra = "From: $name <$email>"; 

		mail ($recipient, $subject, $message, $extra); 


		print "Many Thanks $name! for contacting us, we shall get back to you as soon as possible...";
	}
} else { ?><form action="http://www.***********.net/contact.php" method="post" name="form1">
	<table width="100%" border="0" cellspacing="5" cellpadding="0">
          <tr>
            <td width="61%" class="formTitles">Name:</td>
          </tr>
          <tr>
            <td><input name="name" type="text" class="formInformation" id="name" size="45" /></td>
          </tr>
          <tr>
            <td class="formTitles">Company:</td>
          </tr>
          <tr>
            <td><input name="company" type="text" class="formInformation" id="company" size="45" /></td>
          </tr>
          <tr>
            <td class="formTitles">Contact No: </td>
          </tr>
          <tr>
            <td><input name="telNum" type="text" class="formInformation" id="telNum" size="45" /></td>
          </tr>
          <tr>
            <td class="formTitles">Email:</td>
          </tr>
          <tr>
            <td><input name="email" type="text" class="formInformation" id="email" size="45" /></td>
          </tr>
        </table>

	  <br />
    <table width="100%" border="0" cellspacing="5" cellpadding="0">
          <tr>
            <td class="formTitles">What would you like to know? </td>
          </tr>
          <tr>
            <td><textarea name="message" cols="45" rows="5" class="formInformation" id="message"></textarea></td>
          </tr>
          <tr>
            <td><input name="Submit" type="submit" class="submit" value="Submit" /></td>
          </tr></table>
    </form>
<?php } ?>

 

I'm no php wizard and a friend of mine did it on this form for me, so i have no idea why its doing it, the form is sending fine just whether the fields are filled in or not.

 

I'm worrying this could leave it open to spam attacks anything i can add to to help that as well?

 

Many thanks for any help, i'm sure i am being blind or something.

 

Cheers

Link to comment
Share on other sites

i aint to php genius either butttt i think its because you are using OR and maybe the brackets around the $_POST things could be affecing it. rather than OR, try | since that is the correct comparison operator to use, i think :) hope that helps

 

so

(($_POST["name"] == "") OR ($_POST["email"] == "") OR ($_POST["telNum"] == ""))

 

would become

($_POST["name"] == "" | $_POST["email"] == "" | $_POST["telNum"] == "")

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.