?
Solved

form processing

Posted on 2000-03-22
10
Medium Priority
?
218 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
Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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 …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

650 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