Jump to content

Form Validation


gaszer

Recommended Posts

I apologize - I'm totally lost with what is probably the simplest of answers... not being a coder, my head is hurting after many hours.

 

All I have to do is validate a string passed from a one text field input form with an exact match.

 

I have a validation in the process script if there is nothing entered (I think):

 

 

<?php

// Receiving variables

@$promocode = addslashes($_POST['promocode']);

// Validation

if (strlen($promocode) == 0 )

{

die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid Promo Code</font></p>");

}

echo("<h3>Thank you! Your promotional code has been accepted.</h3> <a href=https://www.someplace.com>Click here to complete your offer</a>");

?>

 

I would just like to validate an exact string and have it return the echo message.

 

Thanks for your patience. Think I need another beer...

Link to comment
https://forums.phpfreaks.com/topic/270558-form-validation/
Share on other sites

If your promotional code must be one from an exact list, you would store that list in a database and check if the entered value was in the database. If your promotional code must only match a specific format, you would test in your php code for that format. Since you haven't stated exactly what the limits/rules are for what you are trying to do, we don't have enough information to help you.

Link to comment
https://forums.phpfreaks.com/topic/270558-form-validation/#findComment-1391691
Share on other sites

If your promotional code must only match a specific format, you would test in your php code for that format. Since you haven't stated exactly what the limits/rules are for what you are trying to do, we don't have enough information to help you.

 

That's exactly what I'm trying to do - vaildate that exact string (with the hash tag) - I just don't know what code to use. As I mentioned, I have the code for vaildating whether something is entered, I just need another "if" statement like this:

 

if (strlen($promocode) == 0 )

{

die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid Promo Code</font></p>");

}

Link to comment
https://forums.phpfreaks.com/topic/270558-form-validation/#findComment-1391698
Share on other sites

Yes... I really apologize for being such a dunderhead. Think I solved it.

 

I guess all I really had to do was an if else statement like this:

 

 

if ( $promocode == "#BC3333" ) {

echo("<h3>Thank you! Your promotional code has been accepted.</h3>");

} else {

echo "The code you entered is incorrect. Please return and try again.";

}

Link to comment
https://forums.phpfreaks.com/topic/270558-form-validation/#findComment-1391712
Share on other sites

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.