1
tonyboy
Class XoopsThemeForm
  • 2002/6/27 14:51

  • tonyboy

  • Just popping in

  • Posts: 1

  • Since: 2002/5/30


Hello,

I am creating my module in which there is a form with scrollbar list.
The xoopsFormValidate function test an empty string with the operator == \"\".
how to do to test the backspace in the string ?
The xoopsFromValidate is defined inside class XoopsThemeForm.
An idea ?
Best regards

Tonyboy

2
onokazu
Re: Class XoopsThemeForm
  • 2002/6/28 3:45

  • onokazu

  • XOOPS Founder

  • Posts: 617

  • Since: 2001/12/13


xoopsFormValidate function is a javascript function.
It is used when the form is actually displayed.

3
zer0fill
Re: Class XoopsThemeForm
  • 2004/8/8 4:06

  • zer0fill

  • Not too shy to talk

  • Posts: 137

  • Since: 2003/12/2


is there an option to do a server-side check than having us do our own validation?

ex
FROM
if (!empty($_POST['email']) && !empty($_POST['title']) && !empty($_POST['address']))
{
 
// save to db
}
else
{
 
$errors = array();
 if (empty(
$_POST['email']) {$errors[] = 'Missing Email<br />';}
 if (empty(
$_POST['title']) {$errors[] = 'Missing Title<br />';}
 if (empty(
$_POST['address']) {$errors[] = 'Missing Address<br />';}
 
$xoopsTpl->assign('errors',$errors);
}

TO
if ($form->validate($_POST)) // or $_GET wherever the data is coming from
{
 
// save to db
}
else
{
 
$xoopsTpl->assign('errors',$form->errors());
}


We would have all the form assignments (addElement()) at the top

4
skalpa
Re: Class XoopsThemeForm
  • 2004/8/8 8:34

  • skalpa

  • Quite a regular

  • Posts: 300

  • Since: 2003/4/16


Not yet, but I have already redone all this layer in the CVS repository, and it will be possible in 2.1+
$form->loadValues$_POST );
if (
$form->validate()) {


Not far...

skalpa.>

5
zer0fill
Re: Class XoopsThemeForm
  • 2004/8/8 9:43

  • zer0fill

  • Not too shy to talk

  • Posts: 137

  • Since: 2003/12/2


Thanks skalpa. For those who just can't wait, I've developed my own (simplistic) validation function

Source
/**           
* @author zer0fill, Sun Aug 08 02:34:28 PDT 2004       
* @desc Validates required input fields. Returns a preformatted string if there's an error     
* @return string|null        
* @param array $required (key=name / value=displayed error)         
*/ 
function validate($required)
{
    
// prep the error message, if any    
    
$message ='';
    
// setup a loop on each required field than doing it manually line by line    
    
foreach ($required as $key=>$item)
    {
      
// find the missing required fields (javascript disabled on user's end)
      
if (empty($_POST[$key])) {$message .= $item.', ';}
    }

    
// A missing field was detected
    
if (!empty($message))
    {
      
// setup the error message and remove the trailing `, `
      
$message '<div class="errorMsg">Missing Required Field(s): '.substr($message,0,-2).'</div>';
      return 
$message;
    }
}


Example
$required = array( 'office_id'=>'Office'
                      
,'role_id'=>'Role'
                      
,'type_id'=>'Type'
                      
,'title'=>'Title'
                      
,'fname'=>'First Name'
                      
,'lname'=>'Last Name'
                      
);
    
$errors validate($required);
    if (empty(
$errors))
    {
      
// save to db
    
}
    else
    {
      
$xoopsTpl->assign('errors',$errors);
    }


Output
<div class="errorMsg">Missing Required Field(s): OfficeRoleTypeTitleFirst NameLast Name</div>


BTW, did you also make regex checks like proper phone format inputs, email, at least x chars, etc (kinda like PEAR's $form->addRule()) ?

6
skalpa
Re: Class XoopsThemeForm
  • 2004/8/8 10:39

  • skalpa

  • Quite a regular

  • Posts: 300

  • Since: 2003/4/16


Yep...
There's already Required / Length / Regexp, and you can make your own validators.
In fact, I could say our framework will be some kind of a mix between the 2.0 classes and PEAR::QuickForm (at least feature-wise, I recoded everything as I think both overuse get/set methods, which I dont like considering we're using PHP).
- You'll be able to modify ALL the elements attributes
- There's the validators stuff implemented
- I'm thinking about adding some of the QF custom elements, although this hasn't been done yet (@ least the "Advanced checkbox", and maybe others, like the "autocomplete" input control)
- You'll be able to attach an object to a form (well, the reality is going to be a bit longer than the following sample, but I think you'll get the point)

$form->attachObject( &$source );
$form->loadValues$_REQUEST );
if ( 
$form->validate(true) ) {
    
$handler->update$source );
}


skalpa.>

7
gordman
Re: Class XoopsThemeForm
  • 2007/9/14 15:02

  • gordman

  • Just popping in

  • Posts: 11

  • Since: 2007/9/7 1


Well it looks like you are handling it alright, i haven't tried it yet but I have your post as a tutorial. Thanks! You really helped.


Fake College Degree

Login

Who's Online

193 user(s) are online (125 user(s) are browsing Support Forums)


Members: 0


Guests: 193


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits