Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent: Sending form via mail - after validating fields.

Status
Not open for further replies.

MakeItSo

Programmer
Oct 21, 2003
3,316
DE
Hi friends,

I'm having somewhat of a problem here.
I have created a form with dozens of fields, some of which I have declared "required" fields.
I have also added a button to the form "send", which will simply execute the menu item "email" to mail the filled-in form to a recipient.
Alas, although I have set the "required" property of some fields, Acrobat will obviously not validate them before sending. It will send even if required fields are empty.
:-(

What I have been trying to do is to run a Javascript function in the MouseDown event of the "send" button, which will return TRUE in case all is fine:
Code:
function allgood()
{
 var mel;
 for (var i=0;i<this.numFields;i++)
 {
  var fName=this.getNthFieldName(i);
  var f=this.getField(fName);
  if (f.required && f.text=="")
  {
   mel=mel + fName + ", ";
  }
 }
allgood=(mel=="");
}
How can I use this function to cancel sending the form / executing the "execute a menu item" action on Mouse Up?

Is there any other way to make Acrobat validate the fields before sending?

Thanks a lot!
Andy

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
OK, I've got a little bit further:
I can use the "execMenuItem("AcroSendMail:SendMail")" to send the form, so this way I can cancel sending based on a boolean value.
Alas, "field.required" is not recognised. Obviously I need a different way to read the value of the "required" checkbox of that field. But how?

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Getting closer!

Funnily, the property name is "required" - but not internally; there it is called "mandatory". [rolleyes]
This is what I got now:
Code:
allgood();
function allgood()
{
 var mel;
 for (var i=0;i<this.numFields;i++)
 {
  var fName=this.getNthFieldName(i);
  var f=this.getField(fName);
  [b]if (f.mandatory=="enabled"[/b] && f.text=="")
  {
   mel=mel + fName + ", ";
  }
 }
if (mel==""){
app.execMenuItem("AcroSendMail:SendMail");
}
else
{app.alert("Mandatory fields emtpy! Please complete form before sending: " + mel);
}
}
I get no debugger error, yet the output is still wrong;
The var mel remains undefined, which means the condition is never true even when the entire form is empty!
[ponder]

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Got it!!!!!

After googling my fingers off, I finally found a decent guide called
"Developing Acrobat Applications Using Javascript"

"f.required" WAS correct, but one has to exclude "button" fields, and check the value length rather than the text property!

Now this baby does it just fine:
Code:
allgood();
function allgood()
{
 var mel;
 mel=""
 for (var i=0;i<this.numFields;i++)
 {
  var fName=this.getNthFieldName(i);
  var f=this.getField(fName);
  [b]if ((f.type != "button") && f.required && (f.value.length<1))[/b]
  {
   mel=mel + fName + ", ";
  }
 }
if (mel==""){
app.execMenuItem("AcroSendMail:SendMail");
}
else
{app.alert("Mandatory fields emtpy! Please complete form before sending: " + mel);
}
}

[flip][bigcheeks]

Hope this helps someone else too!


[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top