[英]Gravity forms jQuery variable to PHP variable populate dynamically
I would like to pass a jQuery variable to php variable, in purpose to make a database selection. 我想将jQuery变量传递给php变量,以进行数据库选择。 Im using gravity forms for the process, the jQuery code get the data from the drop down(2) and add it to another field(5), but i need the selected data from the dropdown to use in database selection:
我使用重力形式进行处理,jQuery代码从下拉列表(2)获取数据并将其添加到另一个字段(5),但是我需要从下拉列表中选择数据才能在数据库选择中使用:
SELECT Title FROM table WHERE Status= $variable
从表中的SELECT标题WHERE Status = $ variable
and the selected value to add to the field 5 in gravity forms. 选择的值以重力形式添加到字段5中。
add_filter("gform_pre_render_1", "monitor_dropdown");
function monitor_dropdown($form){
?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#input_1_2').bind('change', function()
{
//get selected value from drop down;
var selectedValue = jQuery("#input_1_2").val();
$.post("hold.php", {"data": selectedValue}, function (txt) {
alert(txt);
});
//populate a text field with the selected drop down value
//jQuery("#input_1_5").val(selectedValue);
});
});
</script>
<?php
return $form;
}
hold.php hold.php
add_filter( 'gform_field_value_url_data', 'populate_date' );
function populate_date( $value) {
$value2 = $_POST['data'];
return $value2 ;
}
// OR
$value3 = $_POST['data'];
return $value3;
Even after adding the ajax im not still what i need, is the ajax right? 即使添加了ajax im之后,我仍然不需要,ajax对吗? Or where im wrong ?
还是我错在哪里?
You can handle the Form submission in the $POST
macro variable. 您可以在
$POST
宏变量中处理表单提交。
Your Form must look like this : 您的表格必须如下所示:
<form action="link_to_your_php" method="post">
<input id="input_1_5" name="input_1_5" />
<input type="submit" value="Find" />
</form>
Then you can handle the variable like this. 然后,您可以像这样处理变量。
<?php
$variable = $POST['input_1_5'];
?>
And then make your query 然后进行查询
SELECT Title FROM table WHERE Status=$variable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.