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('[email protected]',$email,$text," ");
header("message_sent.php");

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


?>

[/code]
Link to comment
https://forums.phpfreaks.com/topic/16597-problems-validating-text-message-form/
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('[email protected]',$email,$text," ");
header("message_sent.php");

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


?>

[/code]
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('[email protected]',$email,$text," ");
header("location:index.php?id=message_sent");

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

?>

[/code]
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('[email protected]',$email,$text," ");
header("location:index.php?id=message_sent");

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

?>
[/code]
[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('[email protected]',$email,$text," ");
header("location:index.php?id=message_sent");

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

?>

[/code]
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

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.