Jump to content

Archived

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

Guest kilbad

Problems validating text message form..

Recommended Posts

Guest kilbad
I have this form to enter a text message and e-mail address that then sends the text to me.  I want to add validation to the form, and I think I am close but having problems with the preg_match statement (I think that's the problem..but maybe not).  Would someone be willing to look at my code and see what I am doing wrong?

Thanks so much!

Brendan

[code]

<?php
@extract($_POST);

$email = stripslashes($email);
$text = stripslashes($text);

function check_field1($field_name_1){
if(!preg_match('/^[A-z0-9\._-]+[@][A-z0-9_-]+([.][A-z0-9\._-]+)+[A-z]{2,4}$/',$field_name_1))
return TRUE;
else return FALSE;
}

function check_field2($field_name_2){
if(!preg_match("/[^0-9\ ]+$/",$field_name_2)) return TRUE;
else return FALSE;
}

$error=0;

if(!check_field1($email)){
$error++;
}
if(!check_field2($text)){
$error++;
}

if($error == "0"){

mail('myemail@example.com',$email,$text," ");
header("message_sent.php");

}else{
header("error.php");
}


?>

[/code]

Share this post


Link to post
Share on other sites
Guest kilbad
I changed the code to this, but the form still results in the error page being loading.  I still think it's a problem with my preg_match statements.  Bascally, I am trying to code preg_match statements that only allow characters: A-Z, 0-9, ä, ö, ü, periods, hyphens, spaces, AND (with regard to the e-mail field) the @ symbol...  any suggestions?  thx again

[code]
<?php
@extract($_POST);

$email = stripslashes($email);
$text = stripslashes($text);

function check_field1($field_name_1){

if(!preg_match('/^[a-zA-Z0-9\._-]+[@][A-z0-9_-]+([.][A-z0-9\._-]+)+[a-zA-Z]{2,4}$/',$field_name_1))
return TRUE;
else return FALSE;
}

function check_field2($field_name_2){
if(!preg_match("/[^a-zA-Z0-9\]+$/",$field_name_2)) return TRUE;
else return FALSE;
}


$error=0;

if(!check_field1($email)){
$error++;
}
if(!check_field2($text)){
$error++;
}

if($error == "0"){

mail('myemail@example.com',$email,$text," ");
header("message_sent.php");

}else{
header("error.php");
}


?>

[/code]

Share this post


Link to post
Share on other sites
try this ok

if(!preg_match('/^[a-zA-Z0-9\._-]+@[A-z0-9_-]+([.][A-z0-9\._-]+)+[a-zA-Z]{2,4}$/',$field_name_1))

Share this post


Link to post
Share on other sites
[code]
<?php
if(!eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]+$" ,$$field_name_1)) {

echo " sorry do not use your email address in the text box!";

}
[/code]

tell me if that what you wanted ok.

Share this post


Link to post
Share on other sites
Guest kilbad
Sorry this is taking me so long to figure out... redarrow, I tried your preg_match, and it did not work... here is my code now..  also, I did not follow your last post (with the eregi statement).  I want to be able to have an e-mail validate in field 1.  Field 2 is for the text message.  Again, I am trying to code preg_match statements that only allow characters: A-Z, 0-9, ä, ö, ü, periods, hyphens, spaces, AND (with regard to the e-mail field (field 1)) the @ symbol.  Again, sorry I am php-retarded today!  thx for the help



[code]
<?php
@extract($_POST);

$email = stripslashes($email);
$text = stripslashes($text);

function check_field1($field_name_1){
if(!preg_match('/^[a-zA-Z0-9\._-]+@[A-z0-9_-]+([.][A-z0-9\._-]+)+[a-zA-Z]{2,4}$/',$field_name_1))
return TRUE;
else return FALSE;
}

function check_field2($field_name_2){
if(!preg_match("/[^0-9\ ]+$/",$field_name_2)) return TRUE;
else return FALSE;
}

$error=0;

if(!check_field1($email)){
$error++;
}
if(!check_field2($text)){
$error++;
}

if($error == "0"){

mail('textmessage.secured@kilbad.com',$email,$text," ");
header("location:index.php?id=message_sent");

}else{
header("location:index.php?id=badform");
}

?>

[/code]

Share this post


Link to post
Share on other sites
i dont see what your trying to do can you kindly show the format that you dont wont shown

Share this post


Link to post
Share on other sites
my eregi code is just like preg_match and works as good ok try it your see.

Share this post


Link to post
Share on other sites
Guest kilbad
I'm not sure what you are asking?  If you want the address to the pages I am using, here they are:

The text message form:: http://kilbad.com/index.php?id=test_textmessage
The error page:: http://kilbad.com/index.php?id=badform
The message sent page:: http://kilbad.com/index.php?id=message_sent
And again, here is the code to my text message script, called "secured_process_textmessage.php"::

[code]
<?php
@extract($_POST);

$email = stripslashes($email);
$text = stripslashes($text);

function check_field1($field_name_1){
if(!preg_match('/^[a-zA-Z0-9\._-]+@[A-z0-9_-]+([.][A-z0-9\._-]+)+[a-zA-Z]{2,4}$/',$field_name_1))
return TRUE;
else return FALSE;
}

function check_field2($field_name_2){
if(!preg_match("/[^0-9\ ]+$/",$field_name_2)) return TRUE;
else return FALSE;
}

$error=0;

if(!check_field1($email)){
$error++;
}
if(!check_field2($text)){
$error++;
}

if($error == "0"){

mail('textmessage.secured@kilbad.com',$email,$text," ");
header("location:index.php?id=message_sent");

}else{
header("location:index.php?id=badform");
}

?>
[/code]

Share this post


Link to post
Share on other sites
you still have A-z in your second and third character class.
[code]<?php
preg_match('/^[a-zA-Z0-9\._\-]+@[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9\_\-]+)+[a-zA-Z]{2,4}$/',$field_name_1)
[/code]

Share this post


Link to post
Share on other sites
[code]

<?php
@extract($_POST);

$email = stripslashes($email);
$text = stripslashes($text);

function check_field1($field_name_1){

// eregi checks the email address format.

if(!eregi("^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]+$" ,$field_name_1))
return TRUE;
else return FALSE;
}

function check_field2($field_name_2){
if(!preg_match("/[^0-9\ ]+$/",$field_name_2)) return TRUE;
else return FALSE;
}

$error=0;

if(!check_field1($email)){
$error++;
}
if(!check_field2($text)){
$error++;
}

if($error == "0"){

mail('textmessage.secured@kilbad.com',$email,$text," ");
header("location:index.php?id=message_sent");

}else{
header("location:index.php?id=badform");
}

?>

[/code]

Share this post


Link to post
Share on other sites
there you go WOW preg_match

[code]
<?php
if(preg_match( '/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}$/i' , $field_name_1)
) return true;
?>
[/code]

Share this post


Link to post
Share on other sites
Guest kilbad
ok, I tried the script you posted two ago, and after reading up on eregi, that now makes sense to me.  However, I still get the error page when I try to send a text.  Do I need to be including uppercase A-Z in the eregi too?  Also, is second preg_match wrong if I am trying to validate a message of text?

thanks again

Share this post


Link to post
Share on other sites
Guest kilbad
I did, and got a "Parse error: syntax error, unexpected T_RETURN" after adding in the
[code]if(preg_match( '/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}$/i' , $field_name_1)[/code]

Share this post


Link to post
Share on other sites
missing a closing ):
[code]if(!preg_match( '/^[A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6}$/i' , $field_name_1))
{
  ....
}[/code]

Share this post


Link to post
Share on other sites
Guest kilbad
I finally got it working!  thank you all for your help

Share this post


Link to post
Share on other sites

×

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.