close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Need email to remove empty fields

Thread began 4/15/2019 10:27 am by lr_leal239405 | Last modified 4/26/2019 9:22 am by Ray Borduin | 988 views | 10 replies |

lr_leal239405

Need email to remove empty fields

I have a form with hundreds of fields. I want the email to show only the fields that are populated (that have something on the $_POST). I tried the bottom script - (added 'if(!empty...' line to what was generated by webassist) but it doesn't work:

<?php
if(!empty($_POST)) {
foreach( $_POST as $pkey => $pval ){
if (!RemoveValue($pkey,$remove,$removeBegins,$removeEnds,$removeIncludes)) {
if (get_magic_quotes_gpc()) $pval = stripslashes((is_array($pval)?implode(", ",$pval):$pval));
?>
<tr valign="top">
<th style="font-family: 'Times New Roman', Times, serif; font-size: 10px;width: 134px; text-align: right; padding: 3px 10px 3px 3px; color: #666; font-weight: bold;"><?php echo(str_replace("_"," ",$pkey)); ?>:</th>
<td style="font-family: 'Times New Roman', Times, serif; font-size: 10px;padding: 3px; border-left: 1px solid #DDD; color: #B6B6B6;"><?php echo(str_replace("\n","<BR />",(is_array($pval)?implode(", ",$pval):$pval))); ?></td>
</tr>
<?php
}
}
}
?>

Also, this form if very complex. I have it all built, but I may need your help. I need to get it to populate the db, one line per fieldset. May be hard to explain but you can see my form here: (I believe I have everything else working with some spaghetti code). :)

Thank you!

Sign in to reply to this post

Ray BorduinWebAssist

Try:

php:
<?php

if(!empty($_POST)) {
  foreach( 
$_POST as $pkey => $pval ){
  if (!
RemoveValue($pkey,$remove,$removeBegins,$removeEnds,$removeIncludes)) {
    if (
get_magic_quotes_gpc()) $pval stripslashes((is_array($pval)?implode(", ",$pval):$pval));
      if (
$pval) {
?>
<tr valign="top">
<th style="font-family: 'Times New Roman', Times, serif; font-size: 10px;width: 134px; text-align: right; padding: 3px 10px 3px 3px; color: #666; font-weight: bold;"><?php echo(str_replace("_"," ",$pkey)); ?>:</th>
<td style="font-family: 'Times New Roman', Times, serif; font-size: 10px;padding: 3px; border-left: 1px solid #DDD; color: #B6B6B6;"><?php echo(str_replace("\n","<BR />",(is_array($pval)?implode(", ",$pval):$pval))); ?></td>
</tr>
<?php
      
}
    }
  }
}
?>
Sign in to reply to this post
Did this help? Tips are appreciated...

lr_leal239405

Thanks. That works great.

I need to take each fieldset that has data and populate the db with a row with only fieldsets that have data 1 per fieldset. The forms (it's only one form divided in fieldsets) has lots of repeat data so I need, on Submit, to Insert one row per selected (and populated) fieldset. If I can't do I'm not sure when you're available to contact. Let me know. Thanks.

Here's my form.

UPDATE: Can one bind the same column on a table (for Example, my column named 'Machine', to all fields on form that ask for the Machine name (I have id and name as Machinecs on one and another with Machinews for example)

Sign in to reply to this post

Ray BorduinWebAssist

I think you could add an Insert Record server behavior for each form field, so you would have a bunch of them on the page. Then use a trigger equal to the same form value you are inserting. That would only do the insert if the field has a value.

Sign in to reply to this post
Did this help? Tips are appreciated...

lr_leal239405

ok, I ended up adding many tables and a ton of Insert Records which works fine.

On the Email sent after submit, I'm having trouble "NOT' including a hidden field. on the Block.php that webassist generates I have:

if (!isset($_POST['dropdownws'])) {
$remove[] = "dropdownws";
}
But I don't think the $_POST gets to this page.

I tried it on the form itself
<?php echo((isset($_POST["dropdownws"])?("Anti-Wrinkle Form Specs"):"")); ?>

but it also ignores the $_POST['dropdownws'] code, even though it's checked. Don't know how I should have it or where I should change it.

Thanks Much.

Sign in to reply to this post

Ray BorduinWebAssist

This code makes no sense:
if (!isset($_POST['dropdownws'])) {
$remove[] = "dropdownws";
}

It basically says "If it doesn't exist, remove it".... if something doesn't exist, why would it need to be removed?

It looks like all of your checkboxes have the same name="dropdownws". Try changing them all to: name="dropdownws[]"

Sign in to reply to this post
Did this help? Tips are appreciated...

lr_leal239405

So I need a hidden field for the db, but not for the email sent. Since there are so many forms in one form I only want the populated fields but since that field is always populated it always shows even though there's no other data in that particular form (within the forms form) :). Here's what the email looks like:

QUOTE REQUEST FORM
Form Submitted 4-23-2019 | 7:04 PM UTC


Applicationcs:
csFormName: Core Support Form Specs
linebreakx:

dropdownws: on
wsFormName: Anti-Wrinkle Form Specs
abrFormName: Adjustable bowed roller Form Specs
fbrFormName: Fixed Bowed Roller Form Specs
AntiWrinkleGroup 3: Scroll Roll
Machinesr: 1
Materialsr: 1
Materialthicknessminsr: 1
Materialthicknessmaxsr: 1
Widthminsr: 1
Widthmaxsr: 1
Webtensionminsr: 1
Webtensionmaxsr: 1
Machinespeedsr: 1
Webwrapanglesr: 1
Webwandersr: 1
Notessr: 1
srFormName: 'Scroll roll form Specs
apFormName: Adjusta-Pull Form Specs
stFormName: Standard Trim Removal Form Specs
smFormName: Standard Matrix Removal Form Specs
frtrimFormName: Fox TrimAway Form Specs
fmrFormName: FOX Matrix Form Specs
tcFormName: Trim Chopper Form Specs
sscFormName: Safety Chuck Form Specs
sshFormName: Shaft Holders Form Specs
rmbFormName: Mounting Block Form Specs
irFormName: Idler roller Form Specs
brFormName: Brake Form Specs
ehrFormName: Heated Roller Form Specs
nraFormName: Nip Roller Assembly Form Specs
draFormName: Dancer Roller Assembly Form Specs
isaFormName: Inline Slitting Assembly Form Specs
sctFormName: Shear Cut Edge Trim Assembly Form Specs
usFormName: Unwind Stand Assembly Form Specs
rsFormName: Rewind Stand Assembly Form Specs
cmaFormName: Web Accumulator Form Specs


I don't want all these fields to show up, like rsFormName, ehrFormName, irFormName etc. I only want them to show up if a checkbox (the checkbox that expands the form) is checked. I guess the problem is not the Email Sent code but in the forms If, Then statement. I got my logic wrong I guess: In the hidden fields value, I write:

<?php echo((isset($_POST["dropdownws"])?("Anti-Wrinkle Form Specs"):"")); ?>

It doesn't see if the dropdownws is set. So, it sends no info. I don't know how to write it without expressly putting it in value="Anti-Wrinkle Form Specs" and having it (and all) show up on the email.

I also had tried : (this is the whole input field)

<input type="hidden" id="csFormName" name="csFormName" value="<?php if(isset($_POST["dropdowncs"])) { echo "Core Support Form Specs"; } ?>"

Sorry if I'm confusing you.

Thanks much.

Sign in to reply to this post

Ray BorduinWebAssist

In order to check if a checkbox is checked, you will have to give it a unique name, or use an array for the name. So, update the checkboxes from name="dropdownws" to: name="dropdownws[]".

Then you will have to also give the checkboxes a value to identify which one is checked. So the first one might have: name="dropdownws[]" value="CoreSupport"

Then on the top of the page you can use something like:

<?php
if (!isset($_POST["dropdownws"]) || !in_array("CoreSupport",$_POST["dropdownws"])) {
$removeBegins[] = "CoreSupport";
}
?>

This will check if the checkbox (now an array because of the name) includes the value "CoreSupport" (the value we set). If it doesn't, then it removes all form elements that start with "CoreSupport". You can do the same for the other checkboxes and other fields you want conditionally removed.

Sign in to reply to this post
Did this help? Tips are appreciated...

lr_leal239405

They all already have unique names. There's only one named dropdownws (meaning dropdown for WrinkleStop), then another for dropodowncs (or dropdown for Core Support), etc. They all do start with 'dropdown' though. And, several are allowed to be checkmarked at the same time (I have to limit to 3 but don't have code yet).

Let me see if I can make heads or tails with what you sent.

The form is ready to go Live but just struggling with the email part. Also, I forced a horizontal rule on the email but not sure if there was a better way than a hidden field with a <hr>. That's another question but it's working for now.

Thank you again.

Also, how do I remove the name ($pkey I guess) for anything that starts with the words 'linebreak'. I only want the value <hr> to show on the email.

Sign in to reply to this post

Ray BorduinWebAssist

In that case you could just use:

<?php
if (!isset($_POST["dropdownws"])) {
$removeBegins[] = "CoreSupport";
}
?>

But you would still have to give the checkboxes a value. To remove the label for a particular column but keep it's value you could use:

if (strpos($pkey,"linbreak") === 0) $pkey = "";

Just add it after the other IF statements, but before the value is displayed.

Sign in to reply to this post
Did this help? Tips are appreciated...
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...