Pod post-save helper just on Public Form? - to send email
Is it possible to have an email sent only when a public form is submitted? not when an entry is added or a change is made in the pod in the backend.
The post save helper I'm currently using is:
<?php
wp_mail('alan@email.com','New Business Signup','There is a new business signed up via the form on the site. Please login to approve.');
?>
Thanks
Alan
edited Sep 8 '10 at 11:28
13 Answers
Try using the WP conditional tag is_admin() if you want a helper to ignore actions while in the admin:
<?php
if(!is_admin()) {
wp_mail('alan@email.com','New Business Signup','There is a new business signed up via the form on the site. Please login to approve.');
}
?>
Thanks for the reply Clarinetlord but it doesn't seem to be working. Still sends a mail when I make a change in the admin.
Oh, my mistake. is_admin() only works inside the helper if you're submitting a custom form, not a generated publicForm. You'll need to pass a hidden form value to the helper instead telling it whether it's processing a form from the admin or not.
First, create and attach an input helper to one of your fields that adds another input (hidden) to the form. Any text, number, or slug column works well for this because it's the simplest:
<input type="text" class="<?php echo $css_classes; ?>" id="<?php echo $css_id; ?>" value="<?php echo htmlspecialchars($value); ?>" maxlength="<?php echo ($coltype=='num')?15:128; ?>" /> <input type="hidden" class="form txt is_publicform pods_field pods_field_is_publicform pods_coltype_txt" value="<?php echo !is_admin(); ?>" />
This extra field will pass a 0 or a 1 to indicate whether it's submitted in the admin or not. Now, your post-save helper should look like this:
<?php
if(isset($params->is_publicform && "1" == $params->is_publicform)) {
wp_mail('alan@email.com','New Business Signup','There is a new business signed up via the form on the site. Please login to approve.');
}
?>
Thank you for your help on this but I still cannot get it to work.
I have added the input helper and it is working - i.e. passing a 1 as the value in a hidden input field.
But when I changed my post save helper to what you gave the save/submit button of the pod in wp-admin never gives a success message or goes back to the listing page and the publicform never refreshes the page to blank. They both sort of hang with the submit grayed out. The data is saved. But no email is sent.
edited Sep 27 '10 at 3:03
Please send us an e-mail with access to your WP Installation to view the helpers in question, or package them up and e-mail them as a .txt file to us.
contact (at) podscms.org
Just to mention it - is_admin() (and user levels) doesn't work properly in my installation (and i don't know why), so i've built my own function based on checking roles, i can put it here, if you want.
Try adding something like
if (is_admin()) echo 'wordpress thinks you\'re an admin';
in the helper, and open your form twice: logged off and logged as admin. In my case there was no difference, because is_admin() always returned true.
Still no luck with this and I really need to get it working.
From clarinetlord's post I added the input helper to create a hidden form input in the publinform-
<input type="hidden" class="form txt is_publicform pods_field pods_field_is_publicform pods_coltype_txt" value="1" />
My post save helper looks like this
<?php
if(isset($params->is_publicform) && "1" == $params->is_publicform) {
wp_mail('alan@email.com','New Business Signup','There is a new business signed up via the form on the site. Please login to approve.');
}
?>
But an email is still being sent when I edit a pod in the backend as well as submitting a publicform.
Also is there any way I can include a field from the pod/public form in the email?
wp_mail('alan@email.com','New Business Signup','There is a new business -"FIELD NAME?" signed up via the form on the site. Please login to approve.');
-> Also is there any way I can include a field from the pod/public form in the email?
yes, you can refer to it as $columns['put heremachine name of column that you need']['value']
Thank you Fike, I used this if anybody else needs it:
wp_mail('alan@email.com','New Business Signup','There is a new business '.$columns['name']['value'].' signed up via the form on the site. Please login to approve.');
['name'] being the field I want to display in the email. thanks
@inspiration:
Are you passing a hard-coded "1" value in the hidden input, or do you have the value generate from
<?php echo !is_admin(); ?>
like in my example?
edited Oct 11 '10 at 12:38
Thank you clarinetlord I was using the hidden input and the value was shown on the public form page but it still didn't seem to be working. Was sending mails for both.
However thanks to your help in another question I was able to do exactly what I needed.
http://podscms.org/qna/questions/1011/notification-via-email
edited Oct 11 '10 at 2:12
I've now realised I need to go back to your earlier suggestion Clarinetlord. (The solution in the other post works but I want to send the business a mail when they submit using the publicform and not just when a new pod entry is added e.g. if admin manually add an entry)
I am passing a hard coded 1 using a hidden input and getting this:
<input type="hidden" class="form txt is_publicform pods_field pods_field_is_publicform pods_coltype_txt" name="is_publicform" value="1" />
My post save helper is this.
<?php
if(isset($params->is_publicform && "1" == $params->is_publicform)) {
wp_mail('alan@email.com','New Business Signup','There is a new business signed up via the form on the site. Please login to approve.');
}
?>
But still an email is being sent from publicform and from backend
edited Oct 14 '10 at 10:13
