IF statement not case sensitive

3 posts by 2 authors in: Forums > CMS Builder
Last Post: November 3, 2008   (RSS)

By rjbathgate - November 3, 2008 - edited: November 3, 2008

I’m trying to set up an IF statement which basically compares the contents of a submit <input> with a value in the CMS.

I’ve got it working fine, with the following:

<?php $iscorrect = ($propertiesRecord['answer']) == ($FORM['answer']); ?>
<?php if ($iscorrect): ?>
<h2>RIGHT</h2>
<?php else: ?>
<h2>WRONG</h2>


I just was hoping that the IF statement can be set to ignore case, as at the moment, if the FORM answer is ‘Rob’ and the CMS answer is ‘rob’, it comes through as false.

Is there anyway around this?

Or, if we can't tell the IF function to ignore case, could we force both the CMS input and the FORM input to come through as all UPPERCASE for example. i.e. when ($FORM['answer']) comes through, it is converted to UPPERCASE, similarly with the CMS field 'answer'.


Cheers
Rob

Re: [Dave] IF statement not case sensitive

Thanks Dave, worked fine...

Just as you posted that, I had also come up with this, which also worked, but was a bit more long winded (so sticking with yours!)

<?php $compare = strcasecmp(($propertiesRecord['answer']),($FORM['answer'])); ?>
<?php if ($compare == '0'): ?>
<h2>RIGHT</h2>
<?php else: ?>
<h2>WRONG</h2>
<?php endif; ?>


Cheers