Log in

View Full Version : Help with contact form class update



Michael-D
02-10-2017, 11:40 AM
I'm having trouble updating my cform class, which you built for me a few years back, to reflect the change from President Obama to President Trump as one of the Anti-Spam questions. I changed "Who is the current U.S. President?" => array ("Obama","obama","Barak Obama","Barak H. Obama","Barak Hussein Obama","Barack Hussein Obama II")
// etc. ...

to:

"Who is the current U.S. President?" => array ("Trump","Donald Trump","Donald J. Trump","Donald John Trump")
// etc. ...

but it doesn't work. It has been some time since I messed with the coding here and am obviously missing something else, but what?

Thanks in advance.

jscheuer1
02-10-2017, 12:04 PM
That looks like PHP. Is it?

In any case, with any programming language syntax is very important. A misplaced or missing comma, colon, quote mark, etc. can mess up a little or a lot. Using a word processor to edit instead of a text only editor can introduce erroneous characters. No way to be sure what the problem is from the little you've shown us here.

Michael-D
02-10-2017, 02:45 PM
Thanks for the reply.

Yes, it's PHP.

I use Adobe Dreamweaver and/or Noted ++, which were both used in the construction/editing of the site and form.

If you could tell me what more is needed to be shown I'll post it. I am unsure how much is unsafe however as the coding was not created by me and I was warned about security of not keeping the coding guarded. The coding for these forms is outside my knowledge and CSS is the upper limit for me.

jscheuer1
02-10-2017, 04:08 PM
It's true you shouldn't share your server side code if it shows vulnerabilities. But you code shouldn't be vulnerable to begin with, though sometimes thats hard to avoid, and keeping it hidden makes it safer. So, if we have to, we can have you email me the code. But let's first see if we can fix it without going through that.

Let's try the simplest easiest thing to miss first. At the end of a line of PHP there should be a terminus, a semi-colon unless you're at the end of a closure of curly brackets indicating a loop or conditional, in the middle of a string literal that includes the line break, or using a comma to indicate a continuation of some list of definitions within a larger definition. Without that you get an error. What you have there looks like a definition, so might need a semi-colon. These semi-colons must come before comments. So:


"Who is the current U.S. President?" => array ("Trump","Donald Trump","Donald J. Trump","Donald John Trump") // etc. ...

would maybe be:


"Who is the current U.S. President?" => array ("Trump","Donald Trump","Donald J. Trump","Donald John Trump"); // etc. ...

Maybe, but I don't think so, using => most likely means you're defining the array of names ("Who is the current U.S. President?) as a part of a larger array, so it probably needs to be a comma:


"Who is the current U.S. President?" => array ("Trump","Donald Trump","Donald J. Trump","Donald John Trump"), // etc. ...

separating it from the next definition in the overall array. But it needs something. It can't just end with the ) there. I'd go for the comma first and see if that fixes it.

Michael-D
02-11-2017, 02:02 PM
Hi John,

Thanks again for replying.

You are correct that there is a definition of an array of questions in a question answer map of anti-spam challenges. There are four questions in total with the last two being:

"What is 5-4?" => array ("1","One","one"),
"Who is the current U.S. President?" => array ("Obama","obama","Barak Obama","Barak H. Obama","Barak Hussein Obama","Barack Hussein Obama II")
// etc. ...
);

The one that has Obama as President, and is working, is on my server as above. There is no comma or semi-colon except after the // etc. …) The only difference between the one working, and the Trump version, which doesn’t work, is that for the working version the President question has six options and for the one that doesn’t work there are four. I do not see anything in the coding that relates to how many options there can be per question, so I doubt this is the issue, unless there is a .PHP or CSS file somewhere that is an include that I've forgotten about and needs tweaking too to reflect the change.

Regards,

Michael

jscheuer1
02-11-2017, 04:37 PM
Well, it's correct that the last item in an array needs no terminus (comma in this case). But it can have one. However, if what you say is true, the most likely answer is that you're using something in the trump one that breaks it. Most often this is a missed internal comma or missing " mark or the use of a word processing quotes like “ or ” which lean instead of the straight up and down quote mark ". From what you posted, none of that looks wrong, but I may have missed it, or you may have posted something slightly different than what you have. It wouldn't cause any security issues to post the entire array by cutting and pasting it from your code. That way I could tell those things for sure. If all of that checks out, it must be the number of entries. Try repeating some of the trump ones so that it totals the same as the obama ones did. Or maybe just change the question to:


"Who was the first black U.S. President?" => array ("Obama","obama","Barak Obama","Barak H. Obama","Barak Hussein Obama","Barack Hussein Obama II")

DyDr
02-12-2017, 10:00 AM
I'm wondering what "it doesn't work" looks like for this code? Are you getting a message that the captcha value is incorrect, even when one of the possible answers has been entered, or are you getting some other symptom or error? A php syntax error would either produce a blank page/http 500 error response or a php syntax error, depending on php's error related settings.

I'm also wondering what a "cform class" is, and is part of, since it will be nearly impossible to solve a problem with any code, unless allowing an infinite amount of time, without knowing what exactly the complete code is that reproduces the problem.

Also, text based question/answer captchas, regardless of how many different questions have been defined, are easy to solve, except by the simplest of bots, in which case it is just as effective to use a 'honey pot' captcha (a form field hidden by css that must be empty in the submitted data). All anyone needs to do is enter one of the questions and answers into a bot script, then just keep requesting the page until they get that specific question.

Michael-D
02-14-2017, 02:34 PM
Hi John,

I've worked with this to try to get the "Trump" array to work, and no luck. I've taken your advice and changed the question to "Who was the first black U.S. President?" Thankfully, no issues.

Traq designed this for me and put in all the safety features. The guy is brilliant and talked way over my head most of the time. He and another chap gave me a crash course in CSS as well so I could bring my web site up to par. Hopefully traq will see this, or my post seeking to hire him for a bit of a rework, and enlighten me on what I'm missing.

Grateful for your input and at least the question is such that no error will occur given a new person sits in the White House.

jscheuer1
02-14-2017, 03:14 PM
Well let's hope you get it worked out, because people won't remember forever who Obama was. Even asking the for the current US president is a little unfair for folks living in other countries, or anywhere, who might not be at all into politics.

I did say one thing (that I know of) in this that might be wrong. Just because the new array you wanted is syntactically correct, I assumed it has to be the number of entries. That's a good guess on my part, but there could always be some other issue or combination of issues including or not including that.

Michael-D
02-17-2017, 03:06 PM
Well let's hope you get it worked out, because people won't remember forever who Obama was. Even asking the for the current US president is a little unfair for folks living in other countries, or anywhere, who might not be at all into politics.

Given that my site is regarding maritime history, and has people from the U.S., the U.K., Australia, and other countries, there's no way to be "fair" unless I rotate the question to include monarchs, prime ministers, etc., and I don't want to put that much effort into a simple anti-spam question. I think most people, at least those I would wish to deal with, are of a certain education level that they know the main world political figures, and as most perceive the U.S. to be at the top of the heap, I think most will remember who Obama was. It was simply a "fill" question and not political in nature as I lost interest in politics decades ago. Politics are for two types of fools; those who run for office and those who vote for them, regardless of political affiliation. I personally would like to forget ALL the U.S. Presidents post Reagan, and a number of world leaders globally, but the people mumbled and elected the long stream of disappointments on that list, including the present clown sitting in the White House. It would be nice if there was actually candidates to choose from, but when you draw from a cesspool, you can't expect to pull out anything but waste. It was entertaining seeing the circus act of candidates lined up and perpetually lying through their eye teeth and the coast to coast dullards eating it up like any of it was meaningful and/or worth listening to.

I'm not expecting my site to run but a few more years as I'm wanting to walk away from the field of ships. I've been in it for nearly 50 years. I think that for the next few years people will recall who Obama was, and if they don't they would likely struggle with the other questions of "How many Apples in a dozen", "what is 5 - 4?", etc.


I did say one thing (that I know of) in this that might be wrong. Just because the new array you wanted is syntactically correct, I assumed it has to be the number of entries. That's a good guess on my part, but there could always be some other issue or combination of issues including or not including that.

I too wondered if it is the number of entries, but I can't find anything that would limit/specify that for any or all of the questions. That I cannot means nothing of course as I'm very likely overlooking it, not looking in the right place, or have no idea what I'm looking for.

jscheuer1
02-17-2017, 04:29 PM
Well a history site (be it maritime or whatever) would tend to attract folks who would remember something like that. If you do figure it out, and do keep the site up, please remember what the issue was, because we probably should NOT have:

"Who was the first orange U.S. President?" ;)