【发布时间】:2026-01-30 06:40:01
【问题描述】:
我有一个简单地返回一个值的 php 函数,我想将该值分配给我前端页面的 javascript 代码中的一个变量。
functions.php 中的 email_data() 函数:
function email_data()
{
$a = 0;
$form_to_DB = WPCF7_Submission::get_instance();
if ( $form_to_DB )
$formData = $form_to_DB->get_posted_data();
$type = implode(',', $formData['type']);
$type = $type . ' ' . $formData['type-other'];
$place = implode(',', $formData['place']);
$place = $place . ' ' . $formData['place-other'];
$Postcode = $formData['Postcode'];
$date = $formData['date'];
$location_long = $formData['cf7-location-lng'];
$location_lat = $formData['cf7-location-lat'];
$location_litter = $formData['cf7-location-url'];
$location_litter = $formData['location-340'];
$comment = $formData['comment'];
if ($formData != null)
{
echo "Hi there! I want to report illegal dumping which consists of $type at $place area. The coordinates of the dumping are Lat: $location_lat, Long: $location_long.";
}
else
{
echo "Please fill the above form first!"
}
return $a;
}
我的一个页面上有一些 html 和 javascript 代码,用于显示表单。现在,我希望将 php 代码返回的变量保存在 JS 变量中。我尝试了很多事情,但都没有成功,对不起,我是 WordPress 开发的新手。
【问题讨论】:
标签: javascript php wordpress variables