Jump to content

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

...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

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

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.