{"id":11694787,"date":"2019-07-03T02:03:30","date_gmt":"2019-07-03T02:03:30","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/call-a-php-function-from-submit\/"},"modified":"2019-07-03T02:03:30","modified_gmt":"2019-07-03T02:03:30","slug":"call-a-php-function-from-submit","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/call-a-php-function-from-submit\/","title":{"rendered":"Call a PHP function from submit"},"content":{"rendered":"<p>Hi,<br \/>\nI have a function in functions.php<\/p>\n<pre><code>function updateHasReadFlag($user) {\n  \/\/ I added support for using this function either with user ID or user object\n  if ( $user &amp;&amp; is_int( $user ) ) {\n    $user_id = $user;\n  } else if ( ! empty( $user-&gt;ID ) ) {\n    $user_id = $user-&gt;ID;\n  } else {\n    return;\n  }\n  return update_user_meta( $user_id, &#039;GDPR_TERMS_READ&#039;, true );\n}<\/code><\/pre>\n<p>Now I want to call this function on click of the Accept button from the GDPR pop up.<\/p>\n<pre><code>&lt;form method=&quot;post&quot;&gt;\n            &lt;?php if ($isshortcode == 1) : ?&gt;\n            &lt;input type=&quot;hidden&quot; name=&quot;wptp_popup_id&quot; value=&quot;&lt;?php echo $termspageid; ?&gt;&quot; \/&gt;\n            &lt;?php endif; ?&gt;\n\t\t\t&lt;div class=&quot;tthebutton&quot;&gt;\n\t\t\t\t&lt;input class=&quot;termsagree&quot; name=&quot;wptp_agree&quot; type=&quot;submit&quot; value=&quot;&lt;?php echo $tagree; ?&gt;&quot; \/&gt;\n\t\t\t    &lt;input class=&quot;termsdecline&quot; type=&quot;button&quot; onclick=&quot;window.location.replace(&#039;&lt;?php echo $termsRedirectUrl ?&gt;&#039;)&quot; value=&quot;&lt;?php echo $tdisagree; ?&gt;&quot; \/&gt;\n\t\t\t&lt;\/div&gt;\n\t\t&lt;\/form&gt;<\/code><\/pre>\n<p>How can I do that?<\/p>\n","protected":false},"template":"","class_list":["post-11694787","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/11694787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/11694787\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=11694787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}