gaszer Posted November 11, 2012 Share Posted November 11, 2012 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 More sharing options...
thara Posted November 11, 2012 Share Posted November 11, 2012 sorry.. actually I cant understand what you need... can you elaborate the question? Link to comment https://forums.phpfreaks.com/topic/270558-form-validation/#findComment-1391659 Share on other sites More sharing options...
gaszer Posted November 11, 2012 Author Share Posted November 11, 2012 Just wondering what code I would use to match an exact string passed from a variable from a form... like a preg_match? But I have no idea about the syntax. Link to comment https://forums.phpfreaks.com/topic/270558-form-validation/#findComment-1391663 Share on other sites More sharing options...
gaszer Posted November 11, 2012 Author Share Posted November 11, 2012 In a nutshell, all I'm really trying to do is have a user enter an exact promo code (symbols and letters) on a form, and then be sent to another page. Link to comment https://forums.phpfreaks.com/topic/270558-form-validation/#findComment-1391670 Share on other sites More sharing options...
thara Posted November 11, 2012 Share Posted November 11, 2012 Is it possible to available your promo code in numbers, characters and symbols? and then do you need to check promo code which user have entered? or not then what? Link to comment https://forums.phpfreaks.com/topic/270558-form-validation/#findComment-1391673 Share on other sites More sharing options...
gaszer Posted November 11, 2012 Author Share Posted November 11, 2012 ...feeling lost. As I showed in the code snippet in my first post - all that is doing is checking whether anything was entered in the text input area. I need it to check whether say #BT123 was entered. If not, they are returned to the form. If it is, they move on. Link to comment https://forums.phpfreaks.com/topic/270558-form-validation/#findComment-1391688 Share on other sites More sharing options...
thara Posted November 11, 2012 Share Posted November 11, 2012 why do you use hash # symbol in your code? is it need? Link to comment https://forums.phpfreaks.com/topic/270558-form-validation/#findComment-1391689 Share on other sites More sharing options...
PFMaBiSmAd Posted November 11, 2012 Share Posted November 11, 2012 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 More sharing options...
gaszer Posted November 11, 2012 Author Share Posted November 11, 2012 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 More sharing options...
PFMaBiSmAd Posted November 11, 2012 Share Posted November 11, 2012 So, is the exact format you are trying to test for a '#', followed by two upper-case letters, followed by three numerical characters? Link to comment https://forums.phpfreaks.com/topic/270558-form-validation/#findComment-1391706 Share on other sites More sharing options...
gaszer Posted November 11, 2012 Author Share Posted November 11, 2012 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 More sharing options...
thara Posted November 11, 2012 Share Posted November 11, 2012 how many promocodes do you have? Think, there are 1000 of promocode exits then how can you check those? you may need to check each code.... Link to comment https://forums.phpfreaks.com/topic/270558-form-validation/#findComment-1391714 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.