Jump to content

Recommended Posts

guys,

 

i need help on my form, i wanted to place an validation  message beside my text area

instead of displaying the error message on a separate page.

currently my error message is being displayed on a separate page and what happens

is when the error message appear, the user has to manually click back to the form

and retype the entire form.

 

how do i do this?

this is the current code in my form

and i wanted to have the validation message beside the name, email and contact of the personal information field

form method="post" action="referral.php?id=4">
      <table width="494" border="0" cellspacing="2" cellpadding="0">
        <tr>
          <td colspan="2"> </td>
        </tr>
        <tr>
          <td colspan="2" align="center" bgcolor="#e5e5e5" class="text7">Please make sure that correct information is supplied so we can get back to you. </td>
        </tr>
        <tr>
          <td colspan="2"> </td>
        </tr>
        <tr>
          <td colspan="2" bgcolor="#F7F7F7" class="text6">Your Personal Information </td>
        </tr>
        <tr>
          <td colspan="2" valign="top" class="text6"><img src="../images/main/spacer.gif" width="8" height="6" /></td>
        </tr>
        <tr>
          <td width="119" align="right" class="text6">name : </td>
          <td width="369"><span class="text6">
            <input name="yname" type="text" class="field3" />
          </span></td>
        </tr>
        <tr>
          <td align="right" class="text6">email : </td>
          <td><input name="yemail" type="text" class="field3" /></td>
        </tr>
        <tr>
          <td align="right" class="text6">contact number  : </td>
          <td><input name="ycontact" type="text" class="field3" /></td>
        </tr>
        <tr>
          <td align="right" class="text6">type of scheme : </td>
          <td><select name="inquiry" class="field3">
            <option value="Refer a Friend" selected="selected">--Refer a Friend--</option>
            <option value="Associate Program">--Associate Program--</option>
          </select></td>
        </tr>
        <tr>
          <td align="right" class="text6"> </td>
          <td> </td>
        </tr>
        <tr>
          <td colspan="2" bgcolor="#F7F7F7" class="text6">Your Candidate Information </td>
        </tr>
        <tr>
          <td colspan="2" valign="top" class="text6"><img src="../images/main/spacer.gif" width="8" height="6" /></td>
        </tr>
        <tr>
          <td width="119" align="right" class="text6">name : </td>
          <td><span class="text6">
            <input name="cname" type="text" class="field3" />
          </span></td>
        </tr>
        <tr>
          <td width="119" align="right" class="text6">email : </td>
          <td><input name="cemail" type="text" class="field3" /></td>
        </tr>
        <tr>
          <td width="119" align="right" class="text6">contact number : </td>
          <td><input name="ccontact" type="text" class="field3" /></td>
        </tr>
        <tr>
          <td width="119" align="right" valign="top" class="text6">profession/ skills : </td>
          <td><textarea name="cskills" cols="35" rows="5" class="field3"></textarea></td>
        </tr>
        <tr>
          <td> </td>
          <td> </td>
        </tr>
        <tr>
          <td colspan="2" bgcolor="#F7F7F7" class="text6">If you have additonal questions/ inquiries, please type it here </td>
        </tr>
        <tr>
          <td colspan="2" valign="top" class="text6"><img src="../images/main/spacer.gif" width="8" height="6" /></td>
        </tr>
        <tr>
          <td> </td>
          <td><textarea name="additonal" cols="35" rows="5" class="field3"></textarea></td>
        </tr>
        <tr>
          <td> </td>
          <td><input name="Submit" type="submit" class="button1" value="Submit" />
                <input type="hidden" name="recipient" value="pixeltrace@gmail.com" />
                <input type="hidden" name="cc" value="pixeltrace@gmail.com" />
          </td>
        </tr>
        <tr>
          <td colspan="2"> </td>
        </tr>
      </table>
    </form>

 

and this is the current code of my referralsend.php

here i would like to happen here is the validation will just be done on the form page

and referralsend.php will just need to send all the information.

<?php

$yname = $_POST['yname'];
$yemail = $_POST['yemail'];
$ycontact = $_POST['ycontact'];
$inquiry = $_POST['inquiry'];
$cname = $_POST['cname'];
$cemail = $_POST['cemail'];
$ccontact = $_POST['ccontact'];
$cskills = $_POST['cskills'];
$recipient = $_POST['recipient'];
$cc = $_POST['cc'];


echo "<CENTER>";
if (($yname == "") || ($yemail == "") || ($ycontact == "")) {
echo '<br><br><span class="text7">Please complete the form. Thanks!</span><br>';
exit;
}

if(!email_is_valid($yemail)) {
echo '<br><br><span class="text7"><br>Email Address Invalid.<br>Please use a valid Email Address</span><br>';
exit;
}

$Message = "";
$Message .= "An Email from: $yname\n";
$Message .= "Contact Number: $ycontact\n";
$Message .= "Email Address: $yemail\n";
$ip = getenv("REMOTE_ADDR");
$Message .="IP address:".$ip."\n";
$Message .= "\n\n";
$Message .= "Type of scheme: $inquiry\n";
$Message .= "Candidate name: $cname\n";
$Message .= "Candidate contact number: $ccontact\n";
$Message .= "Candidate email: $cemail\n";
$Message .= "Candidate skills: $cskills\n";
$Message .= "\n\n";
$Message .= "Additional Questions/Inquiries: $additional\n";
$Message .= "\n\n";



$Header = $email;
$To = "$recipient, $cc";
$Subject = "JH Referral Scheme"; 

// mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported
mail($To,$Subject,$Message,"From: $Header");

echo '<script language=javascript> alert("Your message has been sent!");top.location = "referral.php?id=3";</script>';

function email_is_valid ($email) {
    if(eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $email, $check)){
       if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) ) {
         return TRUE;
       }
       // THIS WILL CATCH DNSs THAT ARE NOT MX.
       if(checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY")){
         return TRUE;
       }
    }
    return FALSE;
  }
?>


 

hope you could help me with this.

 

thanks a lot!

Link to comment
https://forums.phpfreaks.com/topic/41200-solved-need-help-on-form-validation/
Share on other sites

Use this:

if ($yname=='' or $yemail=='' or $yemail==)  { 
         error ('Some required fields are blank.\\n'.
              'Please fill them in and try again.');
    }

 

Use the following code for error and then save it as validate.php and include it as

include("include/validate.php"); at the top of ur php code.

 

validate.php:

<?php 
function error($msg) {    
    ?>
      <script language="JavaScript">     
      <!--
       alert("<?php echo ($msg) ?> ");
        history.back();
   -->
    </script>        
    <?php
    exit;
}
?>

 

I think this will help.

 

hi

its working now

but i am getting an error when sending the complete and correct information

this is the error message that i am getting from line 54

 

Fatal error: Call to undefined function: getmxrr() in c:\hosting\webhost4life\member\diorgrace\new\referral\referralsend.php on line 54

 

what does this mean?

 

this is the current code that i have for this page

<?php

$yname = $_POST['yname'];
$email = $_POST['email'];
$ycontact = $_POST['ycontact'];
$inquiry = $_POST['inquiry'];
$cname = $_POST['cname'];
$cemail = $_POST['cemail'];
$ccontact = $_POST['ccontact'];
$cskills = $_POST['cskills'];
$recipient = $_POST['recipient'];
$cc = $_POST['cc'];


if (($yname == "") || ($email == "") || ($ycontact == "")) {
echo '<script language=javascript> alert("Please complete the form!");history.back();</script>';
exit;
}
if(!email_is_valid($email)) {
echo '<script language=javascript> alert("Please use a valid email address!");history.back();</script>';
exit;
}

$Message = "";
$Message .= "An Email from: $yname\n";
$Message .= "Contact Number: $ycontact\n";
$Message .= "Email Address: $email\n";
$ip = getenv("REMOTE_ADDR");
$Message .="IP address:".$ip."\n";
$Message .= "\n\n";
$Message .= "Type of scheme: $inquiry\n";
$Message .= "Candidate name: $cname\n";
$Message .= "Candidate contact number: $ccontact\n";
$Message .= "Candidate email: $cemail\n";
$Message .= "Candidate skills: $cskills\n";
$Message .= "\n\n";
$Message .= "Additional Questions/Inquiries: $additional\n";
$Message .= "\n\n";




$Header = $email;
$To = "$recipient, $cc";
$Subject = "JH Referral Scheme"; 

// mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported
mail($To,$Subject,$Message,"From: $Header");

echo '<script language=javascript> alert("Your message has been sent!");top.location = "referral.php?id=3";</script>';

function email_is_valid ($email) {
    if(eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $email, $check)){
       if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) ) {
         return TRUE;
       }
       // THIS WILL CATCH DNSs THAT ARE NOT MX.
       if(checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY")){
         return TRUE;
       }
    }
    return FALSE;
  }
?>


 

hope you could help me with this.

 

thanks!

Use only this, u echo the script, dont echo it.

Code:

if ($yname=='' or $yemail=='' or $yemail==)  { 
         error ('Some required fields are blank.\\n'.
              'Please fill them in and try again.');
    }

 

Other thing u did not include the validate.php.

Include it like this:

<?php
include("include/validate.php");
An ur rest of code.

hi,

 

i tried using your codes but regardless whether

i complete the form or not

 

it always prompts the error message

what's wrong with my code?

 

need help.

 

this is the current code that i have

<?php
$yname = $_POST['yname'];
$email = $_POST['yemail'];
$ycontact = $_POST['ycontact'];
$inquiry = $_POST['inquiry'];
$cname = $_POST['cname'];
$cemail = $_POST['cemail'];
$ccontact = $_POST['ccontact'];
$cskills = $_POST['cskills'];
$recipient = $_POST['recipient'];
$cc = $_POST['cc'];

if ($yname=='' or $yemail=='' or $yemail=='')  { 
         error ('Some required fields are blank.\\n'.
              'Please fill them in and try again.');
    }
?>
<?php 
function error($msg) {    
    ?>
      <script language="JavaScript">     
      <!--
       alert("<?php echo ($msg) ?> ");
        history.back();
   -->
    </script>        
    <?php
    exit;
}
?>
<?
$Message = "";
$Message .= "An Email from: $yname\n";
$Message .= "Contact Number: $ycontact\n";
$Message .= "Email Address: $yemail\n";
$ip = getenv("REMOTE_ADDR");
$Message .="IP address:".$ip."\n";
$Message .= "\n\n";
$Message .= "Type of scheme: $inquiry\n";
$Message .= "Candidate name: $cname\n";
$Message .= "Candidate contact number: $ccontact\n";
$Message .= "Candidate email: $cemail\n";
$Message .= "Candidate skills: $cskills\n";
$Message .= "\n\n";
$Message .= "Additional Questions/Inquiries: $additional\n";
$Message .= "\n\n";




$Header = $yemail;
$To = "$recipient, $cc";
$Subject = "JH Referral Scheme"; 

// mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported
mail($To,$Subject,$Message,"From: $Header");

echo '<script language=javascript> alert("Your message has been sent!");top.location = "referral.php?id=3";</script>';

function email_is_valid ($email) {
    if(eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $yemail, $check)){
       if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) ) {
         return TRUE;
       }
       // THIS WILL CATCH DNSs THAT ARE NOT MX.
       if(checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY")){
         return TRUE;
       }
    }
    return FALSE;
  }
?>


 

thanks!

Ok ur code will look this.

Code:

<?php
include("include/validate.php");
$yname = $_POST['yname'];
$email = $_POST['yemail'];
$ycontact = $_POST['ycontact'];
$inquiry = $_POST['inquiry'];
$cname = $_POST['cname'];
$cemail = $_POST['cemail'];
$ccontact = $_POST['ccontact'];
$cskills = $_POST['cskills'];
$recipient = $_POST['recipient'];
$cc = $_POST['cc'];

if ($yname=='' or $yemail=='' or $yemail=='')  { 
         error ('Some required fields are blank.\\n'.
              'Please fill them in and try again.');
    }


$Message = "";
$Message .= "An Email from: $yname\n";
$Message .= "Contact Number: $ycontact\n";
$Message .= "Email Address: $yemail\n";
$ip = getenv("REMOTE_ADDR");
$Message .="IP address:".$ip."\n";
$Message .= "\n\n";
$Message .= "Type of scheme: $inquiry\n";
$Message .= "Candidate name: $cname\n";
$Message .= "Candidate contact number: $ccontact\n";
$Message .= "Candidate email: $cemail\n";
$Message .= "Candidate skills: $cskills\n";
$Message .= "\n\n";
$Message .= "Additional Questions/Inquiries: $additional\n";
$Message .= "\n\n";

$Header = $yemail;
$To = "$recipient, $cc";
$Subject = "JH Referral Scheme"; 

// mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported
mail($To,$Subject,$Message,"From: $Header");

echo '<script language=javascript> alert("Your message has been sent!");top.location = "referral.php?id=3";</script>';

function email_is_valid ($email) {
    if(eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $yemail, $check)){
       if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) ) {
         return TRUE;
       }
       // THIS WILL CATCH DNSs THAT ARE NOT MX.
       if(checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY")){
         return TRUE;
       }
    }
    return FALSE;
  }
?>

 

Now make a folder named 'include' in ur www directory, save the

following code there as validate.php

 

<?php 
function error($msg) {    
    ?>
      <script language="JavaScript">     
      <!--
       alert("<?php echo ($msg) ?> ");
        history.back();
   -->
    </script>        
    <?php
    exit;
}
?>

 

And then run ur page.

Also make sure that ur include/validate.php is accessed by this script.

I mean that give a validate directory here.

include("foldername/validate.php");

hi

 

i tried this but the error message keeps on popping

regardless whether i complete the form or not

 

this is my current code now

<?php
include 'validate.php';
$yname = $_POST['yname'];
$email = $_POST['yemail'];
$ycontact = $_POST['ycontact'];
$inquiry = $_POST['inquiry'];
$cname = $_POST['cname'];
$cemail = $_POST['cemail'];
$ccontact = $_POST['ccontact'];
$cskills = $_POST['cskills'];
$recipient = $_POST['recipient'];
$cc = $_POST['cc'];

if ($yname=='' or $yemail=='' or $yemail=='')  { 
         error ('Some required fields are blank.\\n'.
              'Please fill them in and try again.');
    }


$Message = "";
$Message .= "An Email from: $yname\n";
$Message .= "Contact Number: $ycontact\n";
$Message .= "Email Address: $yemail\n";
$ip = getenv("REMOTE_ADDR");
$Message .="IP address:".$ip."\n";
$Message .= "\n\n";
$Message .= "Type of scheme: $inquiry\n";
$Message .= "Candidate name: $cname\n";
$Message .= "Candidate contact number: $ccontact\n";
$Message .= "Candidate email: $cemail\n";
$Message .= "Candidate skills: $cskills\n";
$Message .= "\n\n";
$Message .= "Additional Questions/Inquiries: $additional\n";
$Message .= "\n\n";

$Header = $yemail;
$To = "$recipient, $cc";
$Subject = "JH Referral Scheme"; 

// mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported
mail($To,$Subject,$Message,"From: $Header");

echo '<script language=javascript> alert("Your message has been sent!");top.location = "referral.php?id=3";</script>';

function email_is_valid ($email) {
    if(eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $yemail, $check)){
       if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) ) {
         return TRUE;
       }
       // THIS WILL CATCH DNSs THAT ARE NOT MX.
       if(checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY")){
         return TRUE;
       }
    }
    return FALSE;
  }
?>

 

and this is what's inside validate.php

<?php

function error($msg) {   

    ?>

      <script language="JavaScript">   

      <!--

      alert("<?php echo ($msg) ?> ");

        history.back();

  -->

    </script>       

    <?php

    exit;

}

?>

 

did i make it right?

 

hi

 

i tried this but the error message keeps on popping

regardless whether i complete the form or not

 

this is my current code now

<?php
include 'validate.php';
$yname = $_POST['yname'];
$email = $_POST['yemail'];
$ycontact = $_POST['ycontact'];
$inquiry = $_POST['inquiry'];
$cname = $_POST['cname'];
$cemail = $_POST['cemail'];
$ccontact = $_POST['ccontact'];
$cskills = $_POST['cskills'];
$recipient = $_POST['recipient'];
$cc = $_POST['cc'];

if ($yname=='' or $yemail=='' or $yemail=='')  { 
         error ('Some required fields are blank.\\n'.
              'Please fill them in and try again.');
    }


$Message = "";
$Message .= "An Email from: $yname\n";
$Message .= "Contact Number: $ycontact\n";
$Message .= "Email Address: $yemail\n";
$ip = getenv("REMOTE_ADDR");
$Message .="IP address:".$ip."\n";
$Message .= "\n\n";
$Message .= "Type of scheme: $inquiry\n";
$Message .= "Candidate name: $cname\n";
$Message .= "Candidate contact number: $ccontact\n";
$Message .= "Candidate email: $cemail\n";
$Message .= "Candidate skills: $cskills\n";
$Message .= "\n\n";
$Message .= "Additional Questions/Inquiries: $additional\n";
$Message .= "\n\n";

$Header = $yemail;
$To = "$recipient, $cc";
$Subject = "JH Referral Scheme"; 

// mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported
mail($To,$Subject,$Message,"From: $Header");

echo '<script language=javascript> alert("Your message has been sent!");top.location = "referral.php?id=3";</script>';

function email_is_valid ($email) {
    if(eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $yemail, $check)){
       if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) ) {
         return TRUE;
       }
       // THIS WILL CATCH DNSs THAT ARE NOT MX.
       if(checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY")){
         return TRUE;
       }
    }
    return FALSE;
  }
?>

 

and this is what's inside validate.php

<?php

function error($msg) {   

    ?>

      <script language="JavaScript">     

      <!--

       alert("<?php echo ($msg) ?> ");

        history.back();

   -->

    </script>       

    <?php

    exit;

}

?>

 

did i make it right?

 

 

If u save ur validate.php in the same folder where ur this page is, then ok

But u forgot to use this () here:

include("validate.php");

 

correct it.

hi,

 

i corrected it already but its still popping up the error message

regardless whether the form is complete or not.

 

this is the current code that i have now

<?php
include("validate.php");
$yname = $_POST['yname'];
$email = $_POST['yemail'];
$ycontact = $_POST['ycontact'];
$inquiry = $_POST['inquiry'];
$cname = $_POST['cname'];
$cemail = $_POST['cemail'];
$ccontact = $_POST['ccontact'];
$cskills = $_POST['cskills'];
$recipient = $_POST['recipient'];
$cc = $_POST['cc'];

if ($yname=='' or $yemail=='' or $yemail=='')  { 
         error ('Some required fields are blank.\\n'.
              'Please fill them in and try again.');
    }


$Message = "";
$Message .= "An Email from: $yname\n";
$Message .= "Contact Number: $ycontact\n";
$Message .= "Email Address: $yemail\n";
$ip = getenv("REMOTE_ADDR");
$Message .="IP address:".$ip."\n";
$Message .= "\n\n";
$Message .= "Type of scheme: $inquiry\n";
$Message .= "Candidate name: $cname\n";
$Message .= "Candidate contact number: $ccontact\n";
$Message .= "Candidate email: $cemail\n";
$Message .= "Candidate skills: $cskills\n";
$Message .= "\n\n";
$Message .= "Additional Questions/Inquiries: $additional\n";
$Message .= "\n\n";

$Header = $yemail;
$To = "$recipient, $cc";
$Subject = "JH Referral Scheme"; 

// mail($To,$Subject,$Message,"From: $Header","-f $EmailAdd"); last parameter might not be supported
mail($To,$Subject,$Message,"From: $Header");

echo '<script language=javascript> alert("Your message has been sent!");top.location = "referral.php?id=3";</script>';

function email_is_valid ($email) {
    if(eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,3}$", $yemail, $check)){
       if ( getmxrr(substr(strstr($check[0], '@'), 1), $validate_email_temp) ) {
         return TRUE;
       }
       // THIS WILL CATCH DNSs THAT ARE NOT MX.
       if(checkdnsrr(substr(strstr($check[0], '@'), 1),"ANY")){
         return TRUE;
       }
    }
    return FALSE;
  }
?>

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.