Comments for HTML Forms generation and validation
01 Aug 2004 12:54
Re: Hidden Fields not showing up
> I love the class, it's really saving me
> time. For some reason I can't seem to
> get any hidden input fields to show up
> when I check the $_POST array. Is there
> something that needs to be set to make
> them be processed?
Never mind.
I found where I needed to put the AddInputPart in the template.
01 Aug 2004 12:36
Hidden Fields not showing up
I love the class, it's really saving me time. For some reason I can't seem to get any hidden input fields to show up when I check the $_POST array. Is there something that needs to be set to make them be processed?
23 Jul 2004 08:44
Re: Server-Side Validation
=====================
In the HTML template its outputted like this:
======================
$myform->getErrorMessage('searchString');
$myform->AddInputPart('searchString');
Sorry it cut my php code
23 Jul 2004 08:41
Re: Server-Side Validation
As I made a fuss and was wrong before!! I thought I'd share a class extension that sets the error messages as an array so you can output error messages where desired on the page:
include_once 'forms.php';
class formsExtension extends form_class {
// Modified Validate Function - to return error messages in an array.
Function Validate(&$verify,$sub_form="")
{
for($inputs=array(), $input_number=0, Reset($this->inputs);$input_numberinputs);Next($this->inputs), $input_number++)
$inputs[]=Key($this->inputs);
for($invalid_parents=$custom=array(),$error=array(),$input_number=0;$input_numberinputs[$field]["TYPE"],"custom"))
{
if(!IsSet($this->inputs[$field]["DiscardInvalidValues"]))
{
$input_error=$this->ValidateInput($field, $this->inputs[$field]["VALUE"], $sub_form);
if(strlen($input_error))
{
if(IsSet($this->inputs[$field]["parent"]))
{
$parent=$this->inputs[$field]["parent"];
$invalid_parents[$parent]=$field;
$invalid_field=$parent;
}
else
{
$invalid_field=$field;
}
$error[$invalid_field] = $input_error;
$verify[$invalid_field]=$this->inputs[$invalid_field]["SubForm"];
}
}
}
else
$custom[]=$field;
}
for($input_number=0;$input_numberinputs[$field]["DiscardInvalidValues"]))
{
$input_error=$this->inputs[$field]["object"]->ValidateInput($this);
if(strlen($input_error))
{
$error[$invalid_field] = $input_error;
$verify[$field]=$this->inputs[$field]["SubForm"];
}
}
}
return($error);
}
function getErrorMessage($errorItem)
{
if (!$this->error_message[$errorItem])
{
return false;
}
else
{
$htmlOutput = "".$this->error_message[$errorItem].'';
print $htmlOutput;
}
}
}
=====================
In the template it looks like this:
=====================
=====================
So I can output any errors where they are caused.
I look forward to the DHTML method also!
Many Thanks Again
Ross
23 Jul 2004 07:08
Re: Server-Side Validation
Sorry Manuel,
I'm being thick - the ValidateServerSideOnly - isn't producing javascript as I said above!
Thank you for you responses - it really is an excellent class!
Ross
23 Jul 2004 05:27
Re: Server-Side Validation
> Manuel - thanks for quick responses,
> unfortunately, it still seems to be
> creating javascript form validation even
> though I have flagged server side
> validation only on?
As I mentioned before, if it stills generates Javascript is due to other reasons. If you can't figure yourself, I need to see your whole form PHP script to tell you why it generates Javascript and what you need to do to avoid it.
> You could have a function that checks
> the returned posted variables against
> any set reg expressions, this then
> returns the error message notice if it
> fails, which in turn can be outputted on
> the page (or template) above the field.
This class always did server side and client side validation. The client side validation support is
optional. To perform server side validation, just call the class functions LoadInputValues and Validate. Please read the documentation and the supplied examples to understand better how it works.
23 Jul 2004 04:55
Re: Server-Side Validation
Manuel - thanks for quick responses, unfortunately, it still seems to be creating javascript form validation even though I have flagged server side validation only on?
> Sure. BTW, I am working on a new version
> that lets you specify a new Javascript
> function that is called when a fields
> does not validate on the client side.
>
> I don't know if that is what you want,
> but this feature allows you to provide
> an alternative validation error notice,
> instead of using the Javascript alert()
> message box that many people do not
> like. The new feature will include a new
> plugin control for displaying messages
> in a DHTML layer. I am still
> experimenting to verify the browser
> compatibility.
%
Sounds great - one idea rather than using DHTML which has cross browser issues and may be easier to code is (not sure though):
You could have a function that checks the returned posted variables against any set reg expressions, this then returns the error message notice if it fails, which in turn can be outputted on the page (or template) above the field.
I think this approach is used in the old oohforms. It may be simpler than the javascript DHTML method and would provide validation for javascript disabled browsers, but on the downside it means that the page would have to be re submitted.
Also would solve my problem as well ;-)
22 Jul 2004 17:18
Re: Server-Side Validation
> Ideally, what I want to do is catch any
> errors after the user has submitted the
> form. I don't want javascript
> validation to be performed as I really
> want more control on how the validation
> error messages are displayed on page.
Sure. BTW, I am working on a new version that lets you specify a new Javascript function that is called when a fields does not validate on the client side.
I don't know if that is what you want, but this feature allows you to provide an alternative validation error notice, instead of using the Javascript alert() message box that many people do not like. The new feature will include a new plugin control for displaying messages in a DHTML layer. I am still experimenting to verify the browser compatibility.
> However, I do want to set up the reg-ex
> and the error message in the array (as
> it keeps all the html item data
> together).
>
> Is this approach possible with this
> class ?
Sure. The above definition should provide exactly that.
22 Jul 2004 03:53
Re: Server-Side Validation
Hi thanks for your quick reply, I'm sorry I don't think I was very clear so here is some sample code:
Heres a copy of my array set up:
$form->AddInput(array(
'TYPE'=>'text',
'NAME'=>'searchString',
'ID'=>'searchString',
'MAXLENGTH'=>100,
'ValidationOnlyOnServerSide' =>'Y',
'ValidateRegularExpression'=>'^[a-zA-Z0-9_]{1,100}$',
'ValidateRegularExpressionErrorMessage'=>'Please enter valid search text',
'LABEL'=>'searchString',
'VALUE'=>$searchString
));
Ideally, what I want to do is catch any errors after the user has submitted the form. I don't want javascript validation to be performed as I really want more control on how the validation error messages are displayed on page.
However, I do want to set up the reg-ex and the error message in the array (as it keeps all the html item data together).
Is this approach possible with this class ?
Result code
The resulting code can get really messy when working with really big forms, just make sure to comment what you are doing.
It has very good features I really liked.