Jump to content


Problems validating text message form..


  • Please log in to reply
17 replies to this topic

#1 Guest_kilbad_*

Guest_kilbad_*
  • Guests

Posted 04 August 2006 - 10:27 PM

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


<?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");
}


?>



#2 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 04 August 2006 - 10:45 PM

you can't have A-z.. split them into a-zA-Z
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#3 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 04 August 2006 - 10:46 PM

Which check_field. produces an error?

RTFM is an almost extinct art form, it should be subsidized.

#4 Guest_kilbad_*

Guest_kilbad_*
  • Guests

Posted 04 August 2006 - 10:58 PM

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

<?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");
}


?>



#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 04 August 2006 - 11:01 PM

try this ok

if(!preg_match('/^[a-zA-Z0-9\._-]+@[A-z0-9_-]+([.][A-z0-9\._-]+)+[a-zA-Z]{2,4}$/',$field_name_1))
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 04 August 2006 - 11:05 PM

<?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!";

}

tell me if that what you wanted ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 Guest_kilbad_*

Guest_kilbad_*
  • Guests

Posted 04 August 2006 - 11:18 PM

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



<?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");
}

?>



#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 04 August 2006 - 11:25 PM

i dont see what your trying to do can you kindly show the format that you dont wont shown
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 04 August 2006 - 11:30 PM

my eregi code is just like preg_match and works as good ok try it your see.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 Guest_kilbad_*

Guest_kilbad_*
  • Guests

Posted 04 August 2006 - 11:33 PM

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/in...est_textmessage
The error page:: http://kilbad.com/index.php?id=badform
The message sent page:: http://kilbad.com/in...id=message_sent
And again, here is the code to my text message script, called "secured_process_textmessage.php"::

<?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");
}

?>


#11 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 04 August 2006 - 11:38 PM

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

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#12 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 04 August 2006 - 11:40 PM


<?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");
}

?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#13 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 04 August 2006 - 11:45 PM

there you go WOW preg_match

<?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;
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#14 Guest_kilbad_*

Guest_kilbad_*
  • Guests

Posted 05 August 2006 - 12:08 AM

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

#15 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 05 August 2006 - 12:14 AM

have you tried mine?
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#16 Guest_kilbad_*

Guest_kilbad_*
  • Guests

Posted 05 August 2006 - 12:17 AM

I did, and got a "Parse error: syntax error, unexpected T_RETURN" after adding in the
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)


#17 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 05 August 2006 - 03:41 AM

missing a closing ):
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))
{
  ....
}

Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#18 Guest_kilbad_*

Guest_kilbad_*
  • Guests

Posted 05 August 2006 - 02:33 PM

I finally got it working!  thank you all for your help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users