Hello I have a function that passes values to other functions using javascript without reloading page.
The first action of the javascript below gets values from a form and sends to php via a call back function formbuilder_ajax_call. In my php script i return these form values as an array so i can call it in other functions. Below is my code:
Javascript
jQuery("#button_to_load_data").click(function() {
var email = $("#email").val();
var other_email = $("#other_email").val();
var subject = $("#subject").val();
var sender = $("#sender").val();
var message = $("#message").val();
var form_name = $("#form_name").val();
var content = getPlainHtml();
// alert(content);
var data = {
'action' : 'formbuilder_ajax_call', // the name of your PHP function!
'form_content' : content, // another random value we'd like to pass
'email' : email,
'other_email' : other_email,
'subject' : subject,
'sender' : sender,
'message' : message,
'form_name' : form_name,
};
var data1 = {
'action' : 'make_short_code'
};
jQuery.post(ajaxurl, data, function(response) {
jQuery("#receiving_div_id").html(response);
});
jQuery.post(ajaxurl, data1, function(response) {
jQuery("#receiving_div_id").html(response);
});
});
PHP
function formbuilder_ajax_call(){
$form_content = trim($_POST['form_content']); // these values are from a form
$email = trim($_POST['email']);
$other_email = trim($_POST['other_email']);
$subject = trim($_POST['subject']);
$sender = trim($_POST['sender']);
$message = trim($_POST['message']);
$form_name = trim($_POST['form_name']);
$form_array = array();
$form_array = array(
"form_content" => $form_content,
"email" => $email,
"other_email" => $other_email,
"subject" => $subject,
"sender" => $sender,
"message" => $message,
"form_name" => $form_name,
);
return $form_array;
}
function make_short_code() {
$get_mailinfo = formbuilder_ajax_call();
var_dump($get_mailinfo);
}
I am using var_dump to see the content being passed in make_short_code but its only the array key values from formbuilder_ajax_call() that are passed and not the content values that was stored in the array. However the values are passed in the