0

I have this form:

<form class="getCurPd" method="get">
     <input type="hidden" id="lastpid" name="lastpid" value="" />
</form>

With some javascript code I've given dynamic value for that input.And now need to use that value in php code. Here it is:

<?php
 $cur = '<script type="text/javascript">jQuery(document).ready(function(){jQuery("#lastpid").val();})</script>';
 $_terms = wp_get_post_terms($cur, 'product_cat');
 foreach ($_terms as $_term) {
       echo '<a style="color:#333;" href='.get_term_link($_term).'>product cat link</a>'; 
}
?>

But $cur isn't defined think that javascript syntax is wrong. Please help me find it.

aiddev
  • 1,409
  • 2
  • 24
  • 56
  • 1
    What exactly are you trying to achieve? – Ram Feb 09 '15 at 12:06
  • I need to use this jQuery("#lastpid").val() value inside wordpress php function wp_get_post_terms(). – aiddev Feb 09 '15 at 12:07
  • 1
    You totally misunderstand the difference between client-side and server-side code. To achieve what you want you should `post` the value from your form to php controller and deal with posted value. – Aleksei Matiushkin Feb 09 '15 at 12:07
  • @user3090189 , Hi mam , jQuery is client side language , PHP is server side ! :) And please stop using WPress , it is ruining PHP Dev's life and salary since 2002 !! It has NO object oriented support , its base code is Mess. – Pratik Joshi Feb 09 '15 at 12:08
  • If you need to use the value from the hidden field, you can just submit and then use the $_GET var in php – MadsBjaerge Feb 09 '15 at 12:09
  • I know that, and want to know is there any way to do this - write jquery code or pass jquery variable to php? – aiddev Feb 09 '15 at 12:09
  • This question needs to be reopened based on the comment I guess -> `I know that, and want to know is there any way to do this - write jquery code or pass jquery variable to php?` – Pratik Joshi Feb 09 '15 at 12:11
  • I've changed my question's title is it enough, or ask a new question? – aiddev Feb 09 '15 at 12:16

0 Answers0