squemish

Author Topic: ereg to preg_match  (Read 3588 times)

christynne

  • Guest
ereg to preg_match
« on: March 04, 2014, 06:58:54 pm »
I am working on this form: http://www.akspin.com/contact.php.

I am trying to change the ereg to preg_match. Where exactly do I find this code? I can't see to find it in my recaptchalib.php or contact.php. Not sure where else it would be.

Thanks!

Dawn Hawkins

  • Administrator
  • Hero Member
  • *****
  • Posts: 280
Re: ereg to preg_match
« Reply #1 on: March 04, 2014, 07:10:17 pm »
The error is this: Deprecated: Function eregi() is deprecated in /home/akspin52/public_html/contact.php on line 21

so you should look to line 21 of your contact.php

this is the line you are looking for:    } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {

You will need to replace that code with preg_match.

Here's an article on the subject along with some suggestions:

http://www.devthought.com/2009/06/09/fix-ereg-is-deprecated-errors-in-php-53/

christynne

  • Guest
Re: ereg to preg_match
« Reply #2 on: March 04, 2014, 08:02:19 pm »
I changed line 21, however; I am getting this error: The reCAPTCHA wasn't entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol).

I followed the tutorial, but I don't seem to have the two other sections.

http://akspin.com/contact.php

Dawn Hawkins

  • Administrator
  • Hero Member
  • *****
  • Posts: 280
Re: ereg to preg_match
« Reply #3 on: March 04, 2014, 08:14:20 pm »
Please post your modified contact.php file.

Dawn Hawkins

  • Administrator
  • Hero Member
  • *****
  • Posts: 280
Re: ereg to preg_match
« Reply #4 on: March 04, 2014, 08:24:39 pm »
The captcha verification is working fine for me when I enter it correctly, but I do receive this error message: Please check if you've filled all the fields with valid information. Thank you.

This occurs because an error has been found.  Please verify that the field names you are validating are the same as what you have named the fields. 

When I enter the captcha wrong I get the error you mentioned, which is how it should act.


christynne

  • Guest
Re: ereg to preg_match
« Reply #5 on: March 05, 2014, 01:04:43 am »
I got the same error.

I am not finding any thing wrong with the code. Before the ereg to preg_match, the form was working flawlessly. I didn't change anything else. What about the other two section from the link you provided....I didn't see where in the code to update those two.

<?php
//If the form is submitted
if(isset($_POST['submit'])) {

   //Check to make sure that the name field is not empty
   if(trim($_POST['contactname']) == '') {
      $hasError = true;
   } else {
      $name = trim($_POST['contactname']);
   }

   //Check to make sure that the subject field is not empty
   if(trim($_POST['subject']) == '') {
      $hasError = true;
   } else {
      $subject = trim($_POST['subject']);
   }
//Check to make sure sure that a valid email address is submitted
   if(trim($_POST['email']) == '')  {
      $hasError = true;
   } else if (!preg_match("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
      $hasError = true;
   } else {
      $email = trim($_POST['email']);
   }

   //Check to make sure comments were entered
   if(trim($_POST['message']) == '') {
      $hasError = true;
   } else {
      if(function_exists('stripslashes')) {
         $comments = stripslashes(trim($_POST['message']));
      } else {
         $comments = trim($_POST['message']);
      }
   }

  require_once('recaptchalib.php');
  $privatekey = "6Ld4QeUSAAAAAIFhojHdtK08MIYzNOunb8pknsqU";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    // Your code here to handle a successful verification
   
   //If there is no error, send the email
   if(!isset($hasError)) {
      $phone = $_POST['phone'];
      $emailTo = 'djspinentertainment@gmail.com';
      $body = "Name: $name \n\nEmail: $email \n\nPhone: $phone \n\nSubject: $subject \n\nComments:\n $comments";
      $headers = 'From: AKSPIN Contact Form <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

      mail($emailTo, $subject, $body, $headers);
      $emailSent = true;
   }
   
  }

   
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />

<link href="style.css" rel="stylesheet" type="text/css" />
<link href='http://fonts.googleapis.com/css?family=Open+Sans+Condensed:300' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Cabin+Condensed:700' rel='stylesheet' type='text/css'>

<!--Contact Form script and CSS-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
    <script src="jquery.validate.pack.js" type="text/javascript"></script>
   
    <script type="text/javascript">
   $(document).ready(function(){
         $("#contractform").validate();
   });
   </script>

<style type="text/css">
#contact-wrapper {
   width:430px;
   padding-top:5px;
   padding-bottom:20px;
   padding-left:20px;
   padding-right:20px;
}

#contact-wrapper div {
   clear:both;
   margin:1em 0;
}
#contact-wrapper label {
   display:block;
   float:none;
   font-size:16px;
   font-family:Arial, Tahoma, Helvetica, sans-serif;
   color:#FFF;
   width:auto;
}
form#contactform input {
   border-color:#B7B7B7 #E8E8E8 #E8E8E8 #B7B7B7;
   border-style:solid;
   border-width:1px;
   padding:5px;
   font-size:16px;
   color:#333;
}
form#contactform textarea {
   font-family:Arial, Tahoma, Helvetica, sans-serif;
   font-size:100%;
   padding:0.6em 0.5em 0.7em;
   border-color:#B7B7B7 #E8E8E8 #E8E8E8 #B7B7B7;
   border-style:solid;
   border-width:1px;
}
   
   </style>

<title>Alaska Spin Entertainment - &quot;Anchorage's Hottest DJ&quot;</title>


</head>

<body>

<?php @include ('head-inc.php');?>

<div id="wrapper"><!--WRAPPER-->

<div id="nav"><!--NAVIGATION MENU // ROLLOVER-->
<ul>
   <center>
    <li><a class="style1" href="services.php">SERVICES</a></li>
   <li><a class="style1" href="bio.php">BIOGRAPHY</a></li>
    <li><a class="style1" style="padding-right:0px;" href="contact.php">CONTACT</a></li>
    </center>
</ul>
</div><!--nav-->
 

<div style="height:1100px;" id="content">
<div style="width:540px;" id="cont-left">
<h1>Contact</h1>

<p style="font-size:20px; padding-left:20px;">Phone: (907) 230-8326 | <a style="font-size:20px" class="style1" href="mailto:djspinentertainment@gmail.com">DJSpinEntertainment@gmail.com</a></p>

<div id="contact-wrapper">

<!--ReCAPTCHA Theme-->
 <script type="text/javascript">
 var RecaptchaOptions = {
    theme : 'blackglass'
 };
 </script>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" id="contactform">



   <div>
       <label for="name"><strong>Name:</strong></label>
      <input type="text" size="40" name="contactname" id="contactname" value="" class="required" />
   </div>

   <div>
      <label for="email"><strong>Email:</strong></label>
      <input type="text" size="40" name="email" id="email" value="" class="required email" />
   </div>
   
    <div>
      <label for="phone"><strong>Phone:</strong></label>
      <input type="text" size="40" name="phone" id="phone" value="" class="required phone" />
   </div>

   <div>
      <label for="subject"><strong>Subject:</strong></label>
      <input type="text" size="40" name="subject" id="subject" value="" class="required" />
   </div>

   <div>
      <label for="message"><strong>Message:</strong></label>
      <textarea rows="10" cols="40" name="message" id="message" class="required"></textarea>
   </div>
 
   
    <p style="font-size:17px; font-weight:bold; line-height:18px;">Please prove you are not a Robot, type the two words in the white box. Then Send Message.</p>
   
    <!--RECAPTCHA-->
<? require_once('recaptchalib.php');
  $publickey = "6Ld4QeUSAAAAAEwZRcSSbFGY1-rMkrTZpRofOd2b";
  echo recaptcha_get_html($publickey);
  ?>
   
    <script type="text/javascript"
     src="http://www.google.com/recaptcha/api/challenge?k=6Ld4QeUSAAAAAEwZRcSSbFGY1-rMkrTZpRofOd2b">
  </script>
  <noscript>
     <iframe src="http://www.google.com/recaptcha/api/noscript?k=6Ld4QeUSAAAAAEwZRcSSbFGY1-rMkrTZpRofOd2b"
         height="300" width="500" frameborder="0"></iframe><br>
     <textarea name="recaptcha_challenge_field" rows="3" cols="40">
     </textarea>
     <input type="hidden" name="recaptcha_response_field"
         value="manual_challenge">
  </noscript>
 
  <br/>
 
     <input type="submit" value="Send Message" name="submit" />
   
</form>
</div>


</div><!--cont-left-->

<div style="width:470px; margin-top:45px;" id="cont-right">

<?php if(isset($hasError)) { //If errors are found ?>
   <p style="font-size:22px; padding:10px; color:#ff0099; background-color:#CCC" class="error">Please check if you've filled all the fields with valid information. Thank you.</p>
<?php } ?>

<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
   <p style="font-size:22px; padding:10px; color:#ff0099; background-color:#CCC"><strong>Email Successfully Sent!</strong></p>
   <p style="font-size:22px; padding:10px; color:#ff0099; background-color:#CCC">Thank you <strong><?php echo $name;?></strong> for using my contact form! Your email was successfully sent and I will be in touch with you soon.</p>
<?php } ?>

<br/><br/>



</div><!--cont-right-->

</div><!--content-->

</div><!--wrapper-->

<!--<br/><br/><div style="clear:both"></div>-->
<?php @include ('foot-inc.php');?>

</body>
</html>

Dawn Hawkins

  • Administrator
  • Hero Member
  • *****
  • Posts: 280
Re: ereg to preg_match
« Reply #6 on: March 05, 2014, 10:58:42 am »
The other two sections were for different deprecated code, so you did not need to work with those.  In the example that you were working with the code went from this:

    eregi('\.([^\.]*$)', $this->file_src_name, $extension);


to this:

    preg_match('/\.([^\.]*$)/i', $this->file_src_name, $extension);

based on that, it looks like you have left out necessary punctuation.  You have:
} else if (!preg_match("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {

but should have:
} else if (!preg_match("/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$/i", trim($_POST['email']))) {

The pattern (^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$) must be wrapped in a RegExp delimiter (for instance / /).

christynne

  • Guest
Re: ereg to preg_match
« Reply #7 on: March 05, 2014, 06:07:27 pm »
Thanks so much!