The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
|
![]() |
If e-mail field is empty, use this address - Printable Version +- Form Tools (https://forums.formtools.org) +-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1) +--- Forum: General Discussion (https://forums.formtools.org/forumdisplay.php?fid=5) +--- Thread: If e-mail field is empty, use this address (/showthread.php?tid=1895) |
If e-mail field is empty, use this address - M8R-f08t5x - Feb 11th, 2012 http://docs.formtools.org/userdoc/?page=configure_form_email_fields I would like to pinpoint first name and last name to form fields and use same e-mail (my@company.com) for all. This is because the e-mail field can be empty. So how can I edit the code so that if the e-mail field is empty, this address (my@company.com) is used? RE: If e-mail field is empty, use this address - Ben - Feb 11th, 2012 Hey, Huh...! So you want all emails to be sent to the same email address, regardless of the name supplied? Interesting use-case. But you can't really do that without editing the code, unfortunately - and even that may take some work. One solution (simpler, but complete hack) would be to add a hidden field to your form like: Code: <input type="hidden" name="placeholder_email" value="my@company.com" /> Then use that as the recipient email. It's ugly, since it would store that dud field value in every submission, but it would work fine and let you get the job done. - Ben btw, AWESOME forum name. I was 100% sure you were a spammer, so your post was a nice surprise. RE: If e-mail field is empty, use this address - M8R-f08t5x - Feb 11th, 2012 Thank you for the answer! My question was a bit indefinite, sorry. I want the email to be sent FROM the same address, IFuser leaves the email field empty in the form. It's a job application form, and every applicant doesn't an have e-mail address. So if the forms e-mail field is empty, the sender name and address gets messed up in the email message. It shows two senders: firstname@my.server.com, lastname@my.server.com. So I would need to tell the Form Tools this: if the applicant doesn't have an email address, use this address instead as FROM address: my@company.com (for example). RE: If e-mail field is empty, use this address - Ben - Feb 11th, 2012 Ah, I see! Are you using the Swift Mailer module, btw, or the default mail functionality? Just wondering, because you shouldn't see two senders: it *should* just default to "none" in the absence of a valid email address, so I'll log this as a bug. But in the meantime, you could do this with the Submission Pre-Parser module. http://modules.formtools.org/submission_pre_parser/ 1. Just install that module, then create a new rule called "Default email address". 2. For the "When Executed" option, select either the API or "On form submission" checkboxes, depending on your form type. 3. For the PHP code section, add the following code: PHP Code: if (empty($_POST["email"])) You'll need to tweak the $_POST["email"] to whatever field name your email field has. And that should be it! - Ben RE: If e-mail field is empty, use this address - M8R-f08t5x - Feb 12th, 2012 OK, thanks! It worked. Only problem is that in this case, where user has no e-mail address, the user e-mail information is not valid in the database. Maybe I change the e-mail something like no@email.com etc... This should solve it. I use the default e-mail functionality. -M8R-f08t5x ![]() RE: If e-mail field is empty, use this address - Jayce6 - Sep 30th, 2020 Good post I like it RE: If e-mail field is empty, use this address - LoganBayldon - Nov 20th, 2020 You are doing good work |