Jump to content

Problems validating text message form..


Guest kilbad

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]
Link to comment
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]
Link to comment
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]
Link to comment
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]
Link to comment
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]
Link to comment
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
Link to comment
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]
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.