A bit of help for a newbie?

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
only1brucec
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Dec 27, 2018 3:37 pm

Thu Dec 27, 2018 3:41 pm

I’m a marketing guy struggling to hack out a quick change to a form validation script.
What I’m trying to accomplish is to test the subject line of the email form for a specific subject line to see if that subject line has been changed .
So, if the subject line is not equal to the phrase I’m looking for (New Message) then issue an error message and end the script

I have a line in the script already that says

$subject = isset($subject) ? $subject : 'New Message';

I was thinking that I could simply add

if ( $subject !== $New Message ) {
echo '{ "alert": "error", "message": NO GO.!" }';
die;
}


Am I even close?

Any help would be appreciated.

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 775
Joined: Mon Feb 22, 2016 5:52 pm

Thu Dec 27, 2018 4:49 pm

What happened when you tried that?

only1brucec
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Dec 27, 2018 3:37 pm

Fri Dec 28, 2018 5:56 am

Thanks for your reply


Syntax error unexpected boolean

What I have is a script that is checking to see if first name = last name then stop. That part works fine.
What I'm trying to add to it is an or statement that also checks if subject line is not equal to 'Subject Text' then also stop
What I wrote was


$N1=$_POST['template-contactform-fname'];
$N2=$_POST['template-contactform-lname'];

if ( $N1 == $N2 ) || ( $subject !== 'Subject Text' ) {
echo '{ "alert": "error", "message": "Bot <strong>Detected</strong>.! NO GO.!" }';
die;
}

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 775
Joined: Mon Feb 22, 2016 5:52 pm

Fri Dec 28, 2018 10:44 am

The test for an if statement needs to be enclosed by one set of parenthesis, what you have is two sets.

Code: Select all

if ( ($N1 == $N2) || ($subject !== 'Subject Text') ) {
  ...
}

only1brucec
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Dec 27, 2018 3:37 pm

Sun Dec 30, 2018 7:25 am

Perfect, that worked. THANK YOU!

Post Reply