Mandatory fields & empty editboxes

Issues related to forms.
Post Reply
viper83viper
 
 
Posts: 6
Joined: Fri May 24, 2024 12:17 pm

Mandatory fields & empty editboxes

Post by viper83viper »

Hi,

I have 2 questions with regards to a form;

1. I have several editboxes in my project. Some are mandatory to fill in, some are not. When the form is submitted, the non-mandatory edit boxes are empty and visible in the email. Is there a way to remove those empty fields from the email?
(if you have like 100 questions in the form, it would be great to receive an email with only the filled in boxes)

2. When clicking on the submit button, which is part of the form, it tells the user if they missed a mandatory field. Now I added an extra event: onclick > Print Element > LayourGid1.
This works, the user gets the print pop-up and can print the form. After printing it gets submitted and I receive the email with the data. However... the mandatory fields are not checked and can be left empty. How can I print the document and submit the form with one click, including checking the mandatory fields.
(I tried using an icon with 2 events; first event; onclick > Form Submit > LayourGid1. Second event: onclick > Print Element > LayourGid1. But no luck)

Thanks so much!
User avatar
Pablo
 
Posts: 22472
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Mandatory fields & empty editboxes

Post by Pablo »

1. No, unless you write your own script to remove these fields.
2. If you implement an event, then the default behavior will be overwritten.
See also:
viewtopic.php?t=37833
User avatar
BaconFries
 
 
Posts: 5640
Joined: Thu Aug 16, 2007 7:32 pm

Re: Mandatory fields & empty editboxes

Post by BaconFries »

As Pablos reply this would require a "custom" script probably in either jquery or javascript. See the following question at stackoverflow below and a possible solution and I say possible solution with a jsfiddle example. To implement you will need some knowledge of the mentioned scripts and how insert into your html.

https://stackoverflow.com/questions/626 ... rom-a-form
wwonderfull
 
 
Posts: 1439
Joined: Fri Aug 21, 2020 8:27 am
Contact:

Re: Mandatory fields & empty editboxes

Post by wwonderfull »

I think it would need both php and js code editing. Because the client will tell the server that fields are empty or even the php code can verify it server sided so when preparing the email make sure not to include those fields which were empty.

For example:

Name
Email
Message

Now someone wrote not the name but the email and the message which are mandatory but when the form processing code generate the code for the php mailer on the php code the 3 fields exist because the fields exist unless there is a condition which gets added that if a submitted field is empty it would need to exclude those fields when sending the email. Now if we used javascript to do that in client side it is possible, but something has to send the ajex signal to the server that a field was empty, so the server needs to exclude that from the email.
Post Reply