duanmi1900
2017-08-03 00:51
浏览 27
已采纳

在嵌入重力形式中包含变量

I need to add a variable inside an array of an embedding gravity forms to populate 2 hidden fields: email and jobname.

Here is my code:

<?php 

    $email = get_field( "email_application" );
    $jobtitle = get_the_title();

    gravity_form( 5, false, false, false, array('email'=>'echo "$email";','jobname'=>'print "$jobtitle";'), false); 
?>

I know that echo, print or just the variable doesn't work as it show like this in my code:

<input name="input_6" id="input_5_6" type="hidden" value="print $jobtitle" class="gform_hidden" aria-invalid="false">

and

<input name="input_5" id="input_5_5" type="hidden" value="echo "$email";" class="gform_hidden" aria-invalid="false">

Instead I should get:

<input name="input_6" id="input_5_6" type="hidden" value="My job title" class="gform_hidden" aria-invalid="false">

and

<input name="input_5" id="input_5_5" type="hidden" value="myaddress@email.com" class="gform_hidden" aria-invalid="false">

I don't know a lot of PHP so if someone could point me in the right direction.

Thank you.

图片转代码服务由CSDN问答提供 功能建议

我需要在嵌入重力形式的数组中添加一个变量来填充2个隐藏字段:email和jobname。

这是我的代码:

 &lt;?php 
 
 $ email = get_field(“email_application”); 
  $ jobtitle = get_the_title(); 
 
 gravity_form(5,false,false,false,array('email'=&gt;'echo'$ email“;','jobname'=&gt;'print”$ jobtitle“  ;'),false);  
?&gt; 
   
 
 

我知道echo,print或只是变量不起作用,因为它在我的代码中显示如下: \ n

 &lt; input name =“input_6”id =“input_5_6”type =“hidden”value =“print $ jobtitle”class =“gform_hidden”aria-invalid =“false”&gt; 
    
 
 

 &lt; input name =“input_5”id =“input_5_5”type =“hidden”value =  “echo”$ email“;”  class =“gform_hidden”aria-invalid =“false”&gt; 
   
 
 

我应该得到: \ n

 &lt; input name =“input_6”id =“input_5_6”type =“hidden”value =“我的职位”class =“gform_hidden”aria-invalid =“false”&gt; 
   
 
 

 &lt; input name =“input_5”id =“input_5_5”type =“hidden”value =“myaddress  @ email.com“class =”gform_hidden“aria-invalid =”false“&gt; 
   
 
 

我不知道很多PHP所以如果有人可以点 我朝着正确的方向前进。

谢谢。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • donglisi8644 2017-08-03 01:12
    已采纳

    Since you are already using php in the code you showed you can just use variable names as shown in the code below:

    gravity_form( 5, false, false, false, array('email'=>$email,'jobname'=>$jobtitle), false); 
    
    点赞 打赏 评论

相关推荐 更多相似问题