I have a shortcode. With this one, i get the ID (number) of a formular $num_formular. Then, with this one, i had to send all the data in the database.
When I run the following code, it works:
function ss_get_appbenutzer($atts, $content = null){
//global $num_formular;
/* Récupération du numéro du formulaire*/
$atts = shortcode_atts(
array(
'num_formular' => 'NUM_formular'
), $atts);
$num_formular = $atts['num_formular'];
echo 'NUM Formulaire DANS SHORTCODE ='.$num_formular;
}
add_shortcode( 'app-benutzer' , 'ss_get_appbenutzer' );
add_action('gform_after_submission_192', 'msk_gform_process_user_registration_192', 10, 2);
function msk_gform_process_user_registration_192 ($entry, $form) {
echo 'PASSAGE DANS FONCTION msk_gform_process_user_registration_MB --> ok ';
}};
and it prints :
NUM Formulaire DANS SHORTCODE =192 PASSAGE DANS FNCTION msk_gform_process_user_registration_MB --> ok
So it works and the data are in the database.
BUT, i get the number of the formular because it will be various number of formular.
So, i need to have $num_formular as a variable. Then I must use call add_action like this :
function ss_get_appbenutzer($atts, $content = null){
//global $num_formular;
/* Récupération du numéro du formulaire*/
$atts = shortcode_atts(
array(
'num_formular' => 'NUM_formular'
), $atts);
$num_formular = $atts['num_formular'];
echo 'NUM Formulaire DANS SHORTCODE ='.$num_formular;
}
add_shortcode( 'app-benutzer' , 'ss_get_appbenutzer' );
$gform = "'gform_after_submission_".$num_formular."'";
add_action($gform, 'msk_gform_process_user_registration_MB', 10, 2);
function msk_gform_process_user_registration_MB ($entry, $form) {
echo 'PASSAGE DANS FONCTION msk_gform_process_user_registration_MB --> ok ';
}};
But the $num_formular is unknown outside the funtion ss_get_appbenutzer. I tried to use global, but i didn't find something working. And i realized that global is not really a good solution.
Then, i tried to include add_action inside the ss_get_appbenutzer function, like this (i took the code which was working)
function ss_get_appbenutzer($atts, $content = null){
//global $num_formular;
/* Récupération du numéro du formulaire*/
$atts = shortcode_atts(
array(
'num_formular' => 'NUM_formular'
), $atts);
$num_formular = $atts['num_formular'];
echo 'NUM Formulaire DANS SHORTCODE ='.$num_formular;
add_action('gform_after_submission_192', 'msk_gform_process_user_registration_192', 10, 2);
}
add_shortcode( 'app-benutzer' , 'ss_get_appbenutzer' );
function msk_gform_process_user_registration_192 ($entry, $form) {
echo 'PASSAGE DANS FONCTION msk_gform_process_user_registration_MB --> ok ';
}};
but it prints only NUM Formulaire DANS SHORTCODE =192
That means that the add_action, placed here in the ss_get_appbenutzer function, doesn't work (or is not called).
COuld you please give me some hint to make this add_action working?
I am really really stuckked and i tried so many things that i don't know where to search now.
Many thanks for your help
Timama
I have a shortcode. With this one, i get the ID (number) of a formular $num_formular. Then, with this one, i had to send all the data in the database.
When I run the following code, it works:
function ss_get_appbenutzer($atts, $content = null){
//global $num_formular;
/* Récupération du numéro du formulaire*/
$atts = shortcode_atts(
array(
'num_formular' => 'NUM_formular'
), $atts);
$num_formular = $atts['num_formular'];
echo 'NUM Formulaire DANS SHORTCODE ='.$num_formular;
}
add_shortcode( 'app-benutzer' , 'ss_get_appbenutzer' );
add_action('gform_after_submission_192', 'msk_gform_process_user_registration_192', 10, 2);
function msk_gform_process_user_registration_192 ($entry, $form) {
echo 'PASSAGE DANS FONCTION msk_gform_process_user_registration_MB --> ok ';
}};
and it prints :
NUM Formulaire DANS SHORTCODE =192 PASSAGE DANS FNCTION msk_gform_process_user_registration_MB --> ok
So it works and the data are in the database.
BUT, i get the number of the formular because it will be various number of formular.
So, i need to have $num_formular as a variable. Then I must use call add_action like this :
function ss_get_appbenutzer($atts, $content = null){
//global $num_formular;
/* Récupération du numéro du formulaire*/
$atts = shortcode_atts(
array(
'num_formular' => 'NUM_formular'
), $atts);
$num_formular = $atts['num_formular'];
echo 'NUM Formulaire DANS SHORTCODE ='.$num_formular;
}
add_shortcode( 'app-benutzer' , 'ss_get_appbenutzer' );
$gform = "'gform_after_submission_".$num_formular."'";
add_action($gform, 'msk_gform_process_user_registration_MB', 10, 2);
function msk_gform_process_user_registration_MB ($entry, $form) {
echo 'PASSAGE DANS FONCTION msk_gform_process_user_registration_MB --> ok ';
}};
But the $num_formular is unknown outside the funtion ss_get_appbenutzer. I tried to use global, but i didn't find something working. And i realized that global is not really a good solution.
Then, i tried to include add_action inside the ss_get_appbenutzer function, like this (i took the code which was working)
function ss_get_appbenutzer($atts, $content = null){
//global $num_formular;
/* Récupération du numéro du formulaire*/
$atts = shortcode_atts(
array(
'num_formular' => 'NUM_formular'
), $atts);
$num_formular = $atts['num_formular'];
echo 'NUM Formulaire DANS SHORTCODE ='.$num_formular;
add_action('gform_after_submission_192', 'msk_gform_process_user_registration_192', 10, 2);
}
add_shortcode( 'app-benutzer' , 'ss_get_appbenutzer' );
function msk_gform_process_user_registration_192 ($entry, $form) {
echo 'PASSAGE DANS FONCTION msk_gform_process_user_registration_MB --> ok ';
}};
but it prints only NUM Formulaire DANS SHORTCODE =192
That means that the add_action, placed here in the ss_get_appbenutzer function, doesn't work (or is not called).
COuld you please give me some hint to make this add_action working?
I am really really stuckked and i tried so many things that i don't know where to search now.
Many thanks for your help
Timama
After some discussing in the comments, I can surmise that this is your situation:
What it looks like you're attempting to do is add a shortcode to the page with a matching form ID so that when the form is submitted the processing occurs for that form.
There are several problems with this:
The 'proper' way to develop this would be to develop a "feed", which is how Gravity Forms supports developers providing a way to add their functionality to specific forms via the UI. The documentation for creating custom feed types is available here. In your case you would put your registration processing into the process_feed
method of your custom feed.
However, as you've suggested, it is quite a lot of work to create an add-on feed. So, I'm going to suggest a workaround:
gform_after_submission
for all forms and check for this hidden field. If the hidden field is present, process the registration.So, for the first step, add a Hidden field to the forms that you need to be processed. Give it a label that makes sense for you. I'll assume "App Benutzer", just based on the shortcode name.
Now, this is what your code will be:
function msk_gform_process_user_registration_MB( $entry, $form ) {
$fields = $form['fields'];
// Check every field in the form.
foreach ( $fields as $field ) {
// If our hidden field has been added to this form, process the user registration.
if ( $field->label = 'App Benutzer' ) {
// Process user registration here.
}
}
}
add_action( 'gform_after_submission', 'msk_gform_process_user_registration_MB', 10, 2 );
So this solves the problem of allowing non-technical users a way to tell Gravity Forms which forms the user registration should be processed for: They just need to add a Hidden field with the label "App Benutzer".
gform_after_submission_192
has presumably already run by the time the shortcode is printed. Honestly, what you're trying to do doesn't make a lot of sense. Why are you using a shortcode for this> It looks like you want to do something after a Gravity Form is submitted, but why would you use a shortcode to do that? Can you explain in more detail what you're actually trying to accomplish. – Jacob Peattie Commented Feb 20, 2019 at 10:16gform_after_submission
, that runs for every form. Can't you just use that? And what is theapp-benutzer
shortcode for? You've described what the Gravity Forms shortcode is for, but not this one. I don't know why you need this shortcode at all, when you can just useadd_action()
in your functions file outside of a shortcode. – Jacob Peattie Commented Feb 20, 2019 at 11:03