?
Solved

form processing

Posted on 2000-03-22
10
Medium Priority
?
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
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 dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

770 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