Reputation: 139
How can i pass form value to 2 PHP functions. For example this is what am trying to do:
$delegate_name = trim($_POST['delegate_name']);
function certificate_custom_css(){ //function 1
if(($_GET["page"] == "preview_certificate") && ("Clement" == $delegate_name))
{
wp_enqueue_style( 'certificates_stylesheet_base');
wp_enqueue_style( 'certificates_stylesheet_fancy');
wp_enqueue_style( 'certificates_stylesheet_tab3');
}
}
function certificate($delegate_name){ //function 2
return $delegate_name;
}
Upvotes: 1
Views: 53
Reputation: 491
you can do it in following way
function certificate_custom_css($delegate_name){ //function 1
if(($_GET["page"] == "preview_certificate") && ("Clement" == $delegate_name))
{
wp_enqueue_style( 'certificates_stylesheet_base');
wp_enqueue_style( 'certificates_stylesheet_fancy');
wp_enqueue_style( 'certificates_stylesheet_tab3');
}
}
function certificate($delegate_name){ //function 2
return $delegate_name;
}
and can call methods like
$delegate_name = trim($_POST['delegate_name']);
certificate_custom_css($delegate_name);
certificate($delegate_name);
Upvotes: 1
Reputation: 1304
What you have to do in order this to work is, you have to make the function accept an argument like this:
function certificate_custom_css($delegate_name)
And later call it with
certificate_custom_css($delegate_name);
The other way to use it, is to use it as a global:
function certificate(){ //function 2
global $delegate_name;
return $delegate_name;
}
I really really recommend using the first one, unless absolutely necessary to use global
.
There are of course the closures, but I suggest to stick to the first option, if you do not completely understand them. But you can do it like this:
$certificate_custom_css = function() use ($delegate_name) { return $delegate_name;}
You can read some more here and here.
Upvotes: 1