Solved

form processing

Posted on 2000-03-22
10
176 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
ID: 2647188
Do you want it to die; ?
0
 

Expert Comment

by:akf
ID: 2648192
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
ID: 2649446
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
ID: 2650144
&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
ID: 2650151
Note... I rather don't use any javascript.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:oostwijk
ID: 2651327
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
ID: 2651363
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
ID: 2651790
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
ID: 2662812
Works great, thanks !!!
0
 

Expert Comment

by:Remi Komeya
ID: 41812632
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to find "path" in Windows 10 12 57
How to count json data 2 66
Batch File to find and replace a string 15 104
Need a good Angular tutorial 5 71
This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
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.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

920 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

11 Experts available now in Live!

Get 1:1 Help Now