Forum Moderators: coopster
PHP Code:
<?php echo empty($error_msg['lastname']) ? 'class="req"' : ''; ?>
If I understand it right the above is saying EMPTY show class="req" if not nothing shows...which makes since because by default it is empty so class="req" is shown hence the field is highlighted.
Is there anyway to re-write the above or add something after the ? mark so that...
the field isn't highlighted on start
if error highlight - class="req"
if error cleared in that field (and another error in some other field) don't highlight the corrected field anymore?
3 pieces instead of 2?
I appreciate any help on this, I've tried just about all I know to try to get it to work.
[edited by: php4U at 12:57 am (utc) on April 27, 2009]
I am having issues with the following because it isn't the usual if ($var == 'x')
unexpected { in line 207 which is the middle line.
<?php
if (empty($error_msg['lastname'])) { echo ''; }
else (!empty($error_msg['lastname'])) { echo 'class="req"'; }
if (empty($error_msg['lastname'])) { echo ''; }
?>
I've been working with this since your post and can't see where my error is.
<?php
if (empty($error_msg['lastname'])) {
echo "";
} elseif (!empty($error_msg['lastname'])) {
echo "class=\"req\"";
} elseif (!empty($c["lastname"])) {
echo "";
} else {
echo "";
}
?>
<?php get_data("lastname"); ?>is how the data is shown after it posts so the user doesn't have to fill it in again.
get_data comes from this function...
function get_data($var) {
global $c;
if (isset($c[$var])) {
echo $c[$var];
Anyone have any thoughts, or suggestions? Thanks again.
$class = '';
if (error in form field1) {
$class = ' class="req"';
}
print "<input{$class} name="\field1\">";
$class = '';
if (error in form field2) {
$class = ' class="req"';
}
print "<input{$class} name="\field2\">";
the following works to not show the error when there isn't one, and it shows it when there is one.
$class = '';
if (!empty($error_msg['lastname'])) {
$class = ' class="req"';
}
print "{$class}";
The issue I'm running into though is for instance if I have field1 and field2 and the user doesn't fill out either one, both show the error class like it should, but if say only field1 is filled out and the form is re-submitted it shows the value the user input into field1 but still shows the class like there is still an error.
<input name="field1" type="text" class="req" id="field1" value="ABC" size="30">
So I started to think if a value exists like value="ABC" check that as well and don't show the class when something is present. That way it doesn't confuse a user if they have properly filled it in and they still see the highlighted field indicating an error.
I really appreciate your posts. I was on the right track the whole time in thinking that, but that is what I was having difficulty with (everything I tried).
I tried something like this in post 4, but got the same result.
//field isn't empty
elseif (!empty($c["field1"])) {echo "";}
I took another look at the code in your last post, and created a working solution with the following...
$class = '';
if (!empty($error_msg['lastname'])) {
$class = 'class="req"';
}
if (!empty($c["lastname"])) {
$class = '';
}
print "{$class}";
Thanks again