Solved

form processing

Posted on 2000-03-22
10
165 Views
Last Modified: 2016-09-23
I've got this form that a user can fill in. The form-variables look like this..
reg1
reg2
reg3
etc.
Now I want to check if these variables have got characters in it or not.
Herefor I tried to use the following lines. But somehowe it doesn't work correctly. Is there anyway I can make this work ?

sub checkform {
foreach $key (sort keys(%form)) {
next unless($key=~/^reg/);
if ($form{$key}){
  &regform2;
  }else{
  print"Not every field has been filled in.";
  &regform;
  }
  die;
 }
}
0
Comment
Question by:oostwijk
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
Do you want it to die; ?
0
 

Expert Comment

by:akf
Comment Utility
Is &regform2 the action to be taken if all the required fields are filled in? If it is, then you want to call it *after* the next loop. Otherwise you're just testing the first value.

The "die" statement is definitely going to stop things after testing the first field (unless it's empty, in which case you'll execute &regform before die-ing).

Finally, in the "else" clause, I'd say "return &regform" to terminate the checkform routine at that point. This is just my best guess, given that I don't know what your regform and regform2 subroutines do.
0
 
LVL 10

Expert Comment

by:makerp
Comment Utility
do it with client side script ... i.e. put the function in the onSubmit event of a form. if it validates return false and the form wont submit

<SCRIPT LANGUAGE=javascript>
                        function validateDetails(t)
                        {
                              var str = new String(t.product.value);
                              if(t.product.value.length == 0 || str.indexOf('\"') != -1 ||(t.prod_adminisrator_select.selectedIndex == 0 && (t.job_title.value.length == 0 || t.email_address.value.length == 0 || t.contact_details.value.length == 0 || t.login.value.length == 0 || t.password.value.length == 0 || t.prod_adminisrator.value.length == 0)))
                              {alert(\"Please complete all fields !\");
                              return false;}
                              else{return true;}
                        }
                  </SCRIPT>
0
 

Expert Comment

by:quickbasic
Comment Utility
&regform and &regform2 are forms that have to be filled in. They both use form-variables as mentioned in my question. &regform has got the variables reg1 untill reg8
and &regform2 has got the variables reg9 till reg16

I placed the "die" statement temporarily while i'm testing the script.

0
 

Expert Comment

by:quickbasic
Comment Utility
Note... I rather don't use any javascript.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:oostwijk
Comment Utility
Thanks akf, it works fine now, but I've got 1 problem though. I use these lines:

if ($form{'reg1'} ne '') { &checkform; }
else {
&regform;
}

to start the sub 'checkform', all fields will be checked with this code and each give me an error message (which the sub 'error' takes care of) if a field isn't filled in. Except for Reg1 (the first formfield), Checkform sees that it hasn't been filled in but it doesn't jump to the 'error' sub. The error seems to be in the lines that call on 'checkform', cause if I change reg1 in reg2 in that line, the second field doesn't jump to the error sub when it hasn't been filled in.
My sub checkform now looks like this..

sub checkform {
foreach $key (sort keys(%form)) {
next unless($key=~/^reg/);
if ($form{$key}){
  }else{
  &error('empty');
  return &regform;
  }
 }
 &regform2;
}

Does anybody know a different way to call on the sub 'checkform' so that I don't get that strange error ?
0
 

Author Comment

by:oostwijk
Comment Utility
Ps. those comments from quickbasic are mine too. I use that name when I'm at my work.
0
 

Accepted Solution

by:
akf earned 100 total points
Comment Utility
Hi again. Simply this should work if I understand you correctly:

                   &checkform;
 

The " if ($form{'reg1'} ne '')  " would specifically skip calling checkform when $form{'reg1'} is empty.  That would make sense to me if you expected this code to run when someone first viewed the form, as well as when they submitted it: you wouldn't want to show them an error message before they submit anything!

If you do need to test for the form's having been submitted, it would be better to include a hidden field in your form and test for it -- or give the submit button a name and test for its value. That way you won't be messing with your test for required fields.
0
 

Author Comment

by:oostwijk
Comment Utility
Works great, thanks !!!
0
 

Expert Comment

by:Remi Komeya
Comment Utility
Excellent discussion ! Speaking of which , you require a CT DRS REG-1 , We came across a template form here <code>https://goo.gl/ZMpTcu</code>
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now