Jump to content

[SOLVED] validation with formmail


NickG21

Recommended Posts

hey everyone, i am using formmail.php in order to process one of my web forms and send everything out VIA e-mail.  i was wonderig if it was possible to do form validation on the page before it is passed through.  i have coding to verify the e-mail address is a valid domain with fsockopen, also just form fields containing only letters or numbers.  can i pass the values through these functions before they are sent to formmail.php?
thanks in advance
Link to comment
https://forums.phpfreaks.com/topic/32611-solved-validation-with-formmail/
Share on other sites

alright, here is the general php validation i am trying to execute before the information is passed into formmail and below is just a small bit of the html code.
[code]<?php
function checkEmail($email)
{
  if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email))
  {
      return FALSE;
  }
  list($Username, $Domain) = split("@",$email);
  if(getmxrr($Domain, $MXHost))
  {
      return TRUE;
  }
  else
  {
      if(@fsockopen($Domain, 25, $errno, $errstr, 15))
      {
        return TRUE;
      }
      else
      {
        return FALSE;
      }
  }
}
if (isset($_POST['submit'])) {
$company = $_POST['CompanyName'];
$name = $_POST['YourName'];
$email = $_POST['YourEmailAddress'];
$domainName = $_POST['ListOrDomainName'];
$username = $_POST['Username'];
$password = $_POST['Password'];
$credit = $_POST['CreditCardNumber'];
$error1 = '';
$error = array();

if (empty($company))
{
$error[] = "Comapny";
}
if (empty($name))
{
$error[] = "Your Name";
}
elseif (!preg_match("/^([a-zA-Z])+/",$name))
{
  $error[] = "Your Name";
  $name="";
}

if(checkEmail($email) == FALSE)
{
  $error[]="E-Mail Address";
  $email = "";
}
if(empty($username))
{
$error[] = "User Name";
}
if(empty($password))
{
$error[]="Password";
$password.class = "errortext";
}
elseif (strlen($password) < 6)
{
$error[]= "Password Must Contain At Least Six Characters";
}
if(empty($credit)){
$error[]="Credit Card Number";
}
elseif(!preg_match("/^([0-9])+/",$credit))
{
$error[] = "Invalid Credit Card Number";
}

if(count($error) > 0) {
    echo "<big><b>The Following Errors Were Found, Please Re-Enter:</b></big><br/>". implode('<br/>', $error). "</p>";
    } else {
header('Location: ./Thanks.php');
    exit;
  }
}
?>[/code]

[code]<table class="qForm">
<tr>
<td colspan="2" class="header">Contact Information</td>
</tr>
<tr>
<td class="left"><a><span class="<?print $text?>">Company Name:</td>

<td><input name="CompanyName" size="28" value="<?echo "$company"?>"></td>
</tr>
<tr>
<td class="left">Your Name :</td>
<td><input name="realname" size="28" value="<?echo "$name"?>"></td>
</tr>
<tr>
<td class="left">Your Email Address:</td>

<td><input name="email" size="28" value="<?echo "$email"?>"></td>
</tr>
<input type="hidden" name="Subject" value="Cancellation Form" />
<input type="hidden" name="required" value="realname, email, ListorDomainName" />
<input type="hidden" name="recipients" value="[email protected]" />
<td style="padding: 1.5em 0; text-align: center;">
<input type="submit" name="submit" value="Submit" /> 
  <input type="reset" value="Reset" />[/code]
formmail.php is just a general mailing script that is used by a lot of people to easily send e-mails with form data from websites.  sorry, i thought it was more well known than that.  anyway, i figured out my problem, sorry to waste your time

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.