Forums

validation and tabbed form

cjmicro 03 Feb, 2009
Did I read somewhere that the CF validation does not work with a tabbed form?

I need to verify an email address field and when I turn on the validation (either type) I get a parse error on the form.

This is CF 2.3.9 and Joomla 1.0

Thanks for any assistance,
Cheryl
GreyHead 03 Feb, 2009
Hi Cheryl,

What is the error? ChronoForms Validation ignores fields that are hidden - this is often the way that JavaScript tabbing works so fields that can cause a problem. The answer depends on what kind of information you have on your tabs but it can be a bit tricky.

Bob
cjmicro 03 Feb, 2009
The error happens when I turn on verification, either type, and with or without actually setting a field to verify.

Parse error: syntax error, unexpected T_CLASS, expecting ',' or ';' in /home/crptou/public_html/components/com_chronocontact/chronocontact.html.php(74) : eval()'d code on line 275



Can I just insert some type of manual javascript validation rather than using CF?

I put the js in the code block:
function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2) 
  {alert(alerttxt);return false;}
else {return true;}
}
}function validate_form(thisform)
{
with (thisform)
{
if (validate_email(email,"Not a valid e-mail address!")==false)
  {email.focus();return false;}
}
}


Then the following in the "onsubmit" code box

onsubmit="return validate_form(this);"
method="post">
Email: <input type="text" name="email" size="30">


Surprise surprise that didn't seem to work, but I did not get any parse error. Is that the correct way to do it? Just want to validate that they enter an email.

Thanks as always, Bob.
Cheryl
GreyHead 03 Feb, 2009
Hi Cheryl,

I'm a bit baffled by the error message - which version of ChronoForms are you using? I can't see any eval'd code on Line 74 of chronocontact.html.php in either v 3.0 or v 2.5 . . . (I do mess hack my files a bit but stuff usually only moves a line or two). And having an error on line 275 suggests that it's something deep inside the form html?? but that should throw an error on line 349 or thereabouts (in CF 3.0).

Your JavaScript will probably work but to trigger it I think that you need
onsubmit="return validate_form(this);"
in the Form Tag attachment box - code in the OnSubmit boxes isn't run until after submission.

Bob

PS Personally this doens't look as robust an email check as the standard one.
cjmicro 03 Feb, 2009
Using cf 2.3.9 for joomla 1.0

Can i take the verification out of onsubmit and put it somewhere else, like onclick in the field area?

Cheryl
GreyHead 03 Feb, 2009
Hi Cheryl,

OK - I didn't check that combo - line 74 is eval'ing the Form HTML. So you might look at the appropriate line in there.

Yes, you can call the validation from anywhere - probably onBlur in the email text input.

Bob
cjmicro 03 Feb, 2009
Thank you Bob... but the parse error only happens when I turn on validation. I have no idea where to look, but here is line 275 and thereabouts in my html. Do you see the missing ; or ,

line 274  echo 'name="'.$row["Name"].'"';
line 275  echo ' id="'.$buttonid.'" value="ON" onclick="CalcTotal1('.$classcount.', Child1Total, TChild1, TotalFees)"';
line 276  echo '</td>';


Thanks,
Cheryl
GreyHead 03 Feb, 2009
Hi Cheryl,

I've been staring at this and the only thing I can see is that technically there's a semi-colon missing at the end of the onClick statement
echo ' id="'.$buttonid.'" value="ON" onclick="CalcTotal1('.$classcount.', Child1Total, TChild1, TotalFees);"';
that might cause the error.

Bob

PS If you use echo " . . . "; with double quotes you can avoid some of the inner quotes.
echo " id='$buttonid' value='ON' onclick='CalcTotal1($classcount, Child1Total, TChild1, TotalFees);'";
and make the code easier to debug.
cjmicro 03 Feb, 2009
I thank you for staring, but adding the semi colon didn't do it. The form works fine until the validation is turned on, so I'm not sure what could be conflicting or causing it.

Here is the code for that whole area in the form. I did notice there is a > missing in the area in red <input type... then no > so maybe that is it. Not sure why validation would all of a sudden make it not parse, but can you look at this? I did add the semi colon but that didn't help, although it seemed to move the parse error to a different line so maybe it did.

I realize it's not your problem to fix my code, but I don't know where else to go since it only seems to happen when the validation is enabled. (and of course now I need the validation!!) 😶

Ok my red type didn't come up in the code area, it is the part about 3/4 of the way down that shows the font color tag. Sorry.

<?php
global $database;

$query_classes = "SELECT * FROM `basa` ORDER BY `index`";
$database->setQuery($query_classes);
$results= $database->query();
if (!$results) {
    echo "Could not successfully run query ($query_classes) from DB: " . mysql_error();
    exit;
}

echo '<table width="100%" bgcolor="#CCCCFF" style="border-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="0">';
 echo '<tr>';
 echo '<td align="center" valign="top" colspan="4">';
 echo '<h3>Class Selection(s) for Child 1</h3>';
 echo '</td>';
 echo '</tr>';
 echo '<tr><td align="center" valign="top">Class Name</td>
<td align="center" valign="top">Grade</td>
<td align="center" valign="top">Day & Time</td>
<td align="left" valign="top">  Tuition</td>
<td align="left" valign="top">  
    Select</td></tr>';

$classcount = mysql_num_rows($results);
while ($row = mysql_fetch_assoc($results)) {
$buttonid = "button1_".$row["index"];
$hiddenid = "cost1_".$row["index"];
$gradeid = "grade1_".$row["index"];
$dtid = "daytime1_".$row["index"];
$locid = "locat1_".$row["index"];

 
  echo '<tr>';
   echo '<td align="left" valign="top">'.$row["Name"]. '</td>';
   echo '<td align="left" valign="top">'.$row["Grade"]. '</td>';
   echo '<td align="left" valign="top">'.$row["Day_time"]. '</td>';
   echo '<td width="25" align="left" valign="top">$'.$row["Fee"]. '</td>';
 echo '<td align="left" valign="top">  <input type="checkbox" ';
 echo 'name="'.$row["Name"].'"';
 echo ' id="'.$buttonid.'" value="ON" onclick="CalcTotal1('.$classcount.', Child1Total, TChild1, TotalFees)"'; 
 echo '</td>';
echo '<input type="hidden" id="'.$hiddenid.'" name="'.$hiddenid.'" value="'. $row["Fee"].'"/>';
echo '<input type="hidden" id="'.$gradeid.'" name="'.$gradeid.'" value="'. $row["Grade"].'"/>';
echo '<input type="hidden" id="'.$dtid.'" name="'.$dtid.'" value="'. $row["Day_time"].'"/>';
echo '<input type="hidden" id="'.$locid.'" name="'.$locid.'" value="'. $row["Location"].'"/>';
echo '</tr>';
}

?>	
Max_admin 03 Feb, 2009
Hi Cheryl,

you need to close the field tag after :

TChild1, TotalFees)"


with some >

Cheers
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
cjmicro 03 Feb, 2009
Update: if I remove that whole section and block of code, the validation works, so it must be in that area. I guess that's good... narrow it down right? :?

Cheryl
Max_admin 03 Feb, 2009
Well, I didn't read the whole topic posts but did you try my suggestion ?🙂

Cheers
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
cjmicro 03 Feb, 2009
Max, thanks I posted my update before I saw your post.

I thought that was the problem but unfortunately I don't know where to put the > to not cause yet other parse errors. I know that is not your job to teach me... 🙂 I will go research and see what i find. Thank you,

Cheryl
Max_admin 03 Feb, 2009
Hi Cheryl,

this code:
echo '<td align="left" valign="top">  <input type="checkbox" ';
echo 'name="'.$row["Name"].'"';
echo ' id="'.$buttonid.'" value="ON" onclick="CalcTotal1('.$classcount.', Child1Total, TChild1, TotalFees)"';
echo '</td>';


will not generate a complete td and input tag, the input tag is missing its closing > after the onClick event attribute!, it should be :

echo ' id="'.$buttonid.'" value="ON" onclick="CalcTotal1('.$classcount.', Child1Total, TChild1, TotalFees)" >';


Cheers
Max
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
cjmicro 03 Feb, 2009
Thanks Max, something still isn't right and at this point I am probably going to wait til tomorrow, as I'm going crosseyed from ;'>/.,;

😲

Cheryl
GreyHead 04 Feb, 2009
Hi Cheryl,

The problem was around the quoting, the version below works OK - at least it generates good html with the validation on. I made two changes - substituting a temporary variable for $row['Name'] and reversing and simplifying the quotes in the hidden rows - both seemed to be needed. This is just the part of your code that I amended

  echo '<tr>';
    echo '<td align="left" valign="top">'.$row["Name"]. '</td>';
    echo '<td align="left" valign="top">'.$row["Grade"]. '</td>';
    echo '<td align="left" valign="top">'.$row["Day_time"]. '</td>';
    echo '<td width="25" align="left" valign="top">$'.$row["Fee"]. '</td>';
    echo '<td align="left" valign="top">';
    $row_name = $row['Name'];
    echo "<input type='checkbox' name='$row_name' id='$buttonid' value='ON'
    	onclick='CalcTotal1($classcount, Child1Total, TChild1, TotalFees);' />";

    echo "<input type='hidden' id='$hiddenid' name='$hiddenid' value='". $row['Fee']."'/>";
    echo "<input type='hidden' id='$gradeid' name='$gradeid' value='". $row['Grade']."'/>";
    echo "<input type='hidden' id='$dtid' name='$dtid' value='".$row['Day_time']."' />";
    echo "<input type='hidden' id='$locid' name='$locid' value='". $row['Location']."'/>";
    echo '</td>';
  echo '</tr>';

Bob
cjmicro 04 Feb, 2009
Dear Bob,

Thanks to you and Max for taking the time to help some more. The good news is that this does work and I can turn on validation. The bad news is that now my field caculations (Javascript) don't work. I'll look at that more later.

I did notice that in your code the <input type='checkbox'... still doesn't have an ending > tag?? If I add this, it does not parse error, and the tag is ended (I think). Would that be correct? (does not fix calcs though)

echo "<input type='checkbox' name='$row_name' id='$buttonid' value='ON'
       onclick='CalcTotal2($classcount, Child2Total, TChild2, TotalFees);'/>";


The other issue now, is that the validation does not cause the form to fail if the required field is omitted. I can still submit the form (submit is on a later tab). Is that something that can be fixed or does it just not work that way with the tabbed form? In any case, having that popup message that the field is required is better than nothing.

Cheryl
GreyHead 04 Feb, 2009
Hi Cheryl,

Not sure why it would break the JavaScript - could be that some more quoting needs fixing :-(

The particular validation script that ChronoForms uses ignores hidden fields - this is sometimes good and sometimes not but its probably what stops your onsubmit validation. You could tie the validation to "next tab" buttons on each tab though.

Bob
cjmicro 04 Feb, 2009
Oops, just edited my message about the ending tag on the input, must have been while you were typing.

I guess that hidden field thing is what I was remembering having seen somewhere. I think that will be ok, I'll just make the message big and red about validation so it will jump out at them.

Cheryl
GreyHead 04 Feb, 2009
Hi Cheryl,

Yes that tag should be closed - I went back and fixed my post :-(

Bob
cjmicro 05 Feb, 2009
Good news!! It all did work, I had to leave it go for awhile then come back. Instituted the changes you suggested again (on a fresh copy of the form), and validation works (except will still submit but I don't care about that... I just want the red REQUIRED FIELD to hit them in the face.

I truly appreciate all the time you both spent trying to help. The client is very happy and I think I might actually be DONE with it...

I learned a lot, mostly that I need to charge a lot more money for custom stuff like this... :mrgreen:

Cheryl
This topic is locked and no more replies can be posted.