Hello
thank you for the answer
so if i understand correctly the code i showed you is not good. so i have to replace
this code
<?php
function my_pre_save_post( $post_id ) {
// check if this is to be a new post
if( $post_id != 'new' ) {
return $post_id;
}
// Create a new post
$post = array(
'post_status' => 'draft' ,
'post_title' => 'A title, maybe a $_POST variable' ,
'post_type' => 'peche' ,
);
// insert the post
$post_id = wp_insert_post( $post );
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );
?>
by this one
// only relevant arguments are included
$args = array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'peche',
'post_status' => 'draft',
'post_title' => $_POST['acf']['field_XXXXXXX'] // the field key you want to use for title
}
);
Thank you very much for the link
yes that’s what I will do. but now I have another problem with my form, I am posting a new message. Thank you again for all your help
Here I just created a new subdomain I used the basic template
I have deactivated all the templates
I just installed ACF and CPT
I took the example of the site with just a contact form and it still does not work …
it’s still weird
I just corrected the post_type and I gave recipe
I wanted to do a simple test with just sending a simple form …
No I have no plugin that blocks emails since from my hostinger mailbox I made a diversion on my Hotmail box
And I do receive emails on my Hotmail …
Yes I’m convinced the code works, but it’s probably just a little detail
I will try again on a new basic theme
But that doesn’t work either
I will create a new subdomain and try with no plugin and I will get back to you
Thank you again for all
the server’s mail function works, because I have a contact form on another site in php and I do receive an email after sending
many thanks for the help
yes my current form works since the recipes arrive in the recipe post type
but it still does not work with your model
So I tried this model but it doesn’t work either
I am staying with hostinger
in the function.php file
add_action('acf/save_post', 'my_save_post');
function my_save_post( $post_id ) {
// bail early if not a contact_form post
if( get_post_type($post_id) !== 'contact_form' ) {
return;
}
// bail early if editing in admin
if( is_admin() ) {
return;
}
// vars
$post = get_post( $post_id );
// get custom fields (field group exists for content_form)
$name = get_field('name', $post_id);
$email = get_field('email', $post_id);
// email data
$to = '[email protected]';
$headers = 'From: ' . $name . ' <' . $email . '>' . "\r\n";
$subject = $post->post_title;
$body = $post->post_content;
// send email
wp_mail($to, $subject, $body, $headers );
}
and in a contact page
<?php /*Template Name: pagecontactt*/;
acf_form_head();
get_header();
?>
<div id="content">
<?php
acf_form(array(
'post_id' => 'new_post',
'post_title' => true,
'post_content' => true,
'new_post' => array(
'post_type' => 'contact_form',
'post_status' => 'publish'
),
'return' => home_url('merci'),
'submit_value' => 'Send'
));
?>
</div>
<?php get_footer(); ?>
thanks for the help
Does your WP site send emails ok? yes
Is the form on a custom post page for the recipe? Yes
here is the form code
<?php /*Template Name: User Submit*/;?>
<?php acf_form_head(); ?>
<?php get_header(); ?>
<div id="container" >
<div class="row">
<div class="col-sm-12">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<!-- a supprimer si on enlève l'éditeur par défaut -->
<?php the_content(); ?>
<!------------>
<p> <?php the_field('Ingredients'); ?></p>
<p> <?php the_field('Preparation'); ?></p>
<p> <?php the_field('Cuisson'); ?></p>
<p> <?php the_field('Temps'); ?></p>
<p> <?php the_field('Difficulté'); ?></p>
<!-- <p> <?php the_field('image'); ?></p>-->
<p> <?php the_field('gallery'); ?></p>
<?php $options = array('post_id' => 'new',
'field_groups' => array(4),
'post_title' => false,
'post_type' => 'recette',
'post_status' => 'draft',
//'updated_message' => 'Merci pour votre participation!Votre recette sera publiée prochainement',
'return' => home_url('merci'),
//'submit_value' => 'Postez votre recette'
'submit_value' => 'Send'
);
acf_form($options);?>
<?php endwhile; ?>
</div>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
thank you for the correction but unfortunately I do not receive any mail, nor in spam
// Sending email after Front-end post submission
add_action('acf/save_post', 'yourdomain_save_post', 15);
function yourdomain_save_post($post_id) {
// Return if not a post
if( get_post_type($post_id) !== 'recette' ) { // here 'post' will be your post type
return;
}
// Return if editing in admin
if( is_admin() ) {
return;
}
// Vars
$post = get_post( $post_id );
$title = wp_strip_all_tags(get_the_title($post->ID));
$to = "[email protected]";
$subject = "Form submission successful";
$message = "Your message here";
$headers = array(
'Content-Type: text/html; charset=UTF-8',
#'Bcc:' . '[email protected]',
'From: '.get_option( 'blogname' ).' <[email protected]>'
);
// send email
wp_mail($to, $subject, $body, $headers );
}
a very big thank you it works great thank you very much
thanks for your help, i just changed the code again, but i still don’t receive email, nothing in spam either. maybe I indicate in the wrong places my email to receive emails
// Sending email after Front-end post submission
add_action('acf/save_post', 'yourdomain_save_post', 15);
function yourdomain_save_post($post_id) {
// Return if not a post
if( get_post_type($post_id) !== 'recette' ) { // here 'post' will be your post type
return;
}
// Return if editing in admin
if( is_admin() ) {
return;
}
// Vars
$post = get_post( $post_id );
$title = wp_strip_all_tags(get_the_title($post->ID));
$to = "{'[email protected]'}";
$subject = "{$blog_title} :: {$title}";
$message = "Your message here";
$headers = array(
'Content-Type: text/html; charset=UTF-8',
#'Bcc:' . '[email protected]',
'From: '.get_option( 'blogname' ).' <[email protected]>'
);
// send email
wp_mail($to, $subject, $body, $headers );
}
Hello
thanks for the code, but I still do not receive an email, here is my new code
// Sending email after Front-end post submission
add_action('acf/save_post', 'yourdomain_save_post', 15);
function yourdomain_save_post($post_id) {
// Return if not a post
if( get_post_type($post_id) !== 'recette' ) { // here 'post' will be your post type
return;
}
// Return if editing in admin
if( is_admin() ) {
return;
}
// Vars
$post = get_post( $post_id );
$title = wp_strip_all_tags(get_the_title($post->ID));
$to = "{$admin_email}";
$subject = "{$blog_title} :: {$title}";
$message = "Your message here";
$headers = array(
'Content-Type: text/html; charset=UTF-8',
#'Bcc:' . '[email protected]',
'From: '.get_option( 'blogname' ).' <[email protected]>'
);
// send email
wp_mail($to, $subject, $body, $headers );
}
Good evening
I just realized a little problem
On my form and on a trial basis I use an image field and a gallery field (it’s just for testing)
When I am an administrator or editor I can upload images or galleries
But if I am a subscriber or contributor I only know how to upload images
Is it possible to allow subscribers or contributors to upload galleries
good evening jarvis it’s really great a very big thank you for the help
is it possible to achieve an enlargement effect when the mouse is passed over
sorry but now it works so I manage to add photos with my form but when I want to display my gallery with the codes at the beginning of my post, nothing is displayed
Hi jarvis
thank you very much for your help
It’s super nice
But I just realized that I already have a problem when I use my form
When I click on add images nothing happens
The add button turns black
Here are screenshots
These are of course tests that I carry out
<?php /*Template Name: User Submit*/;?>
<?php acf_form_head(); ?>
<?php get_header(); ?>
<div id="container" >
<div class="row">
<div class="col-sm-12">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<!-- a supprimer si on enlève l'éditeur par défaut -->
<!------------>
<p> <?php the_field('Ingredients'); ?></p>
<p> <?php the_field('Cuisson'); ?></p>
<p> <?php the_field('Temps'); ?></p>
<p> <?php the_field('Preparation'); ?></p>
<p> <?php the_field('Difficulté'); ?></p>
<p> <?php the_field('gallery'); ?></p>
<?php $options = array('post_id' => 'new',
'field_groups' => array(4),
'post_title' => true,
'post_type' => 'recette',
'post_status' => 'draft',
//'updated_message' => 'Merci pour votre participation!Votre recette sera publiée prochainement',
'updated_message' => __("Recette publiée", 'acf'),
//'return' => home_url('merci'),
'%post_url%', // Redirect to new post url
'submit_value' => 'Postez votre recette'
//'submit_value' => 'Send'
);
acf_form($options);?>
<?php endwhile; ?>
</div>
</div><!-- #content -->
</div><!-- #primary -->
<?php //get_footer(); ?>
Hello
a big thank you for your
but I just realized that I forgot to check author in the parameters of CPT, so everything works, thank you again
ah okay, a big thank you for the code and the correction
thank you for the answer
but this is at the level of the function file
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.