?
Solved

form processing

Posted on 2000-03-22
10
Medium Priority
?
219 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 85

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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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
 

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 400 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

840 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