Support Forum
Support › MB Frontend Submission › Email notification trouble.Resolved
I need to set up an email notification that goes to my client when someone submits a form from the frontend, but I keep getting errors. Could you walk me through the steps. I was using this from the documentation, and adding my meta box in the brackets.
add_action( 'rwmb_frontend_after_process', function( $config, $post_id ) {
if ( 'my-meta-box' === $config['id'] ) {
wp_mail( '[email protected]', 'New submission', 'A new post has been just submitted.' );
wp_safe_redirect( 'thank-you' );
die;
}
}, 10, 2 );
But I get this error:
Parse error: syntax error, unexpected 'add_action' (T_STRING), expecting function (T_FUNCTION) in /nfs/c12/h07/mnt/220007/domains/devseek.minnesotaee.org/html/wp-content/plugins/mb-frontend-submission/src/Form.php on line 152
Hi Mary,
Looks like you're using a very old version of PHP, probably 5.2. Please ask your host to update it to the latest version (which is 7.3), or any version >= 5.3. The code then will work.
You were correct about the php. I had them change it to 7. But now I get this:
Parse error: syntax error, unexpected 'add_action' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /nfs/c12/h07/mnt/220007/domains/devseek.minnesotaee.org/html/wp-content/plugins/mb-frontend-submission/src/Form.php on line 155
Hi Mary, can you check the line 155 in the file Form.php
? I don't see the add_action
text on that file as the error says:
https://i.imgur.com/YKE6VNJ.png
Anyway, after upgrading to PHP 7, did you check phpinfo()
to make sure it's PHP 7? Some host/server requires to restart the PHP service to work.
I just ran phpinfo and it reports PHP Version 7.2.12. I added code to the form.php and so the line 155 on my file has the first line of the code below:
add_action( 'rwmb_frontend_after_process', function( $config, $post_id ) {
if ( 'my-meta-box' === $config['mymetaboxid#'] ) {
wp_mail( '[email protected]', 'New submission', 'A new post has been just submitted.' );
wp_safe_redirect( 'thank-you' );
die;
}
}, 10, 2 );
Also, this may have nothing to do with it, but your screen shot looks nothing like my form.php file. Here's my file lines 145 - 163
do_action( 'rwmb_frontend_before_process', $this->config );
$object_id = $this->object->save();
$this->object->post_id = $object_id;
do_action( 'rwmb_frontend_after_process', $this->config, $object_id );
return $object_id;
}
/**
* Handling deleting posts by id.
*/
public function delete() {
if ( empty( $this->config['post_id'] ) ) {
return;
}
do_action( 'rwmb_frontend_before_delete', $this->config );
wp_delete_post( $this->config['post_id'] );
do_action( 'rwmb_frontend_after_delete', $this->config, $this->config['post_id'] );
}
I got it. You should not add code directly into the plugin. Because when the plugin updates,your modification will lost.
Instead, please add the code to your theme's functions.php
file, or use a plugin like Code Snippet to add code.
So, just to be safe, I checked the version of Frontend I was using. It was 2.02. I was able to download the newer version from your site. So now we match. I am working in Form.php v 2.04. (NOTE: there was no notice in WordPress of a newer version to update to.)
Anyway, all that said and done, I get the same error - just now on a different line
Parse error: syntax error, unexpected 'add_action' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /nfs/c12/h07/mnt/220007/domains/devseek.minnesotaee.org/html/wp-content/plugins/mb-frontend-submission/src/Form.php on line 134
Looks like we were sending t the same time.
I want to circle back to the directions.
"The plugin will look for a template file with the following order:
Inside a folder mb-frontend-submission
of your child theme
Inside a folder mb-frontend-submission
of your parent theme
In the plugin’s templates folder
"
I had intended to do that once I could see it worked in the parent. But if I understand you correctly, it does not do in the templates folder in my child theme. It goes into functions.
Hi Mary,
That part of the documentation is for the template files, such as template for confirmation message, template for post title field, etc.
Template files are not for custom actions like what you tried to do with add_action
. So, please use the theme's functions.php
file or Code Snippets plugin to add your custom actions, as I suggested above.