|
 Brian Read - 2007-06-19 12:01:34
here is my set-up:
$form->AddInput(array(
"TYPE"=>"text",
"NAME"=>"loginname",
"ID"=>"loginname",
"MAXLENGTH"=>50,
"LABEL"=>"User Name",
"ACCESSKEY"=>"F",
"VALUE"=>$userdata['loginname'],
"ValidateServerFunction"=>"CheckUsernameUnique",
"ValidateServerFunctionErrorMessage"=>"User Name not unique - suggest you use your full email address?",
"SIZE"=>50
));
But the CheckUsernameUnique function does not seem to be called.
I have tried something very simple:
function CheckUsernameUnique($username)
{
return false;
}
but the field is still passed as ok.
Any ideas?
 Manuel Lemos - 2007-06-19 21:34:51 - In reply to message 1 from Brian Read
The right name of the attribute is ValidationServerFunction .
 Brian Read - 2007-06-20 10:08:53 - In reply to message 2 from Manuel Lemos
oh, so it is, sorry to have bothered you. You know you can look at these things for hours and not spot that...
Incidentally, I am delighted with your form class, it is saving me no end of headaches in terms of validation and set-up of a site.
Many thanks for your dedication and effort.
cheers
Brian
 Brian Read - 2007-06-25 11:18:43 - In reply to message 3 from Brian Read
Ok, got the name right now, but can't seem to get it to do what i want.
I start by checking to see if the field has been changed by the user. i currently have this:
function CheckUsernameUnique($username)
{
if (!IsSet($form->Changes['loginname']))
# no change in username
return true;
else {
return false;
}
}
However the validation always seems to come back "true" whether I leave the field alone or make a change to it. It always takes the "then" branch. Am I using the Changes array correctly?
 Form Class - 2007-06-25 14:37:18 - In reply to message 4 from Brian Read
Invoke LoadInputValues() before accessing the Changes array.
HTH
 Manuel Lemos - 2007-06-25 14:50:44 - In reply to message 4 from Brian Read
That $form variable may need to be declared as global.
 Brian Read - 2007-06-25 17:16:37 - In reply to message 6 from Manuel Lemos
I tried "global $form" in the function definition, but it made no difference.
Loadinputvalues is called immediately before the call to "validate", as per the example in the package.
here is the new function:
function CheckUsernameUnique($username)
{
global $form;
if (!IsSet($form->Changes['loginname']))
# no change in username
return true;
else
return false;
}
$form is created here:
$form=new form_class;
$form->NAME="Member_details_form";
$form->METHOD="POST";
$form->ACTION="";
$form->debug="trigger_error";
$form->ResubmitConfirmMessage=
"Are you sure you want to submit this form again?";
$form->OutputPasswordValues=1;
$form->OptionsSeparator="<br />\n";
$form->ShowAllErrors=1;
$form->InvalidCLASS='invalid';
# $form->InvalidSTYLE='background-color: #ffcccc; border-color: #000080';
$form->ErrorMessagePrefix="- ";
$form->ErrorMessageSuffix="";
and the loginname entry is set-up here:
$form->AddInput(array(
"TYPE"=>"text",
"NAME"=>"loginname",
"ID"=>"loginname",
"MAXLENGTH"=>50,
"LABEL"=>"User Name",
"ACCESSKEY"=>"F",
"VALUE"=>$userdata['loginname'],
"ValidationServerFunction"=>"CheckUsernameUnique",
"ValidationServerFunctionErrorMessage"=>"User Name not unique - suggest you use your full email address?",
"SIZE"=>50
));
and the processing is done here:
$form->LoadInputValues($form->WasSubmitted("doit"));
$verify=array();
if($form->WasSubmitted("doit"))
{
if(($error_message=$form->Validate($verify))=="")
{
$doit=1;
}
else
{
$doit=0;
$error_message=nl2br(HtmlSpecialChars($error_message));
}
}
else
{
$error_message="";
$doit=0;
}
I presume the validationserver function is called as part of the "Validate" call?
Cheers
Brian
 Manuel Lemos - 2007-06-26 05:03:41 - In reply to message 7 from Brian Read
That seems correct. It will always validate when the submitted values did not change compared to what they had before calling LoadInputValues. Otherwise it will fail validation. Isn't that what you want?
 Brian Read - 2007-06-26 06:57:16 - In reply to message 8 from Manuel Lemos
I am assumimg that above code will allow me to proceed when the value does not change, but fail when the value does change. Am I misunderstanding the "loadinputvalues" function?
 Brian Read - 2007-06-26 07:03:30 - In reply to message 9 from Brian Read
<follow up> Actually as I am using !IsSet() then I am also assuming that this will come back true if the values have not changed, and false otherwise. This is what does not appear to be happening (it always comes back true).
B.
|