{"id":1531,"date":"2014-10-13T15:17:09","date_gmt":"2014-10-13T15:17:09","guid":{"rendered":"https:\/\/ibex.tech\/javascript\/?p=1531"},"modified":"2022-02-17T07:14:46","modified_gmt":"2022-02-17T07:14:46","slug":"text-area-dialog-that-then-calls-php-function","status":"publish","type":"post","link":"https:\/\/ibex.tech\/javascript\/jquery\/dialogs\/examples-dialogs\/text-area-dialog-that-then-calls-php-function","title":{"rendered":"Text Area Dialog that then calls PHP Function"},"content":{"rendered":"<h5>\nThe HTML<br \/>\n<\/h5>\n<h5>\nHead<br \/>\n<\/h5>\n<pre>\r\n<code>\r\n&lt;!-- JQUERY UI --&gt;\r\n&lt;script src=&quot;https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.7.2\/jquery.min.js&quot; type=&quot;text\/javascript&quot;&gt;&lt;\/script&gt; &lt;!--Should be first script imported\/first script on the page--&gt;\r\n&lt;link rel=&quot;stylesheet&quot; href=&quot;http:\/\/ajax.googleapis.com\/ajax\/libs\/jqueryui\/1.8.9\/themes\/smoothness\/jquery-ui.css&quot; type=&quot;text\/css&quot; media=&quot;all&quot; \/&gt;\r\n&lt;script src=&quot;http:\/\/ajax.googleapis.com\/ajax\/libs\/jqueryui\/1.8.9\/jquery-ui.min.js&quot; type=&quot;text\/javascript&quot;&gt;&lt;\/script&gt;\r\n\r\n\r\n&lt;script type=&quot;text\/javascript&quot;&gt;\r\n\t\/\/----------------------------------------\r\n\t\/\/----- OUR JQUERY ENTER TEXT DIALOG -----\r\n\t\/\/----------------------------------------\r\n\t$(&quot;.our_jquery_dialog&quot;).live(&#39;click&#39;, function(e)\r\n\t{\r\n\t\te.preventDefault();\r\n\t\t\r\n\t\t\/\/----- OPTIONAL GET SPECIAL VALUES INCLUDED IN THE LINK -----\r\n\t\tvar usage_id = $(this).attr(&quot;usage_id&quot;);\r\n\t\t\r\n\t\t\/\/----- THE CONTENT DISPLAYED IN THE DIALOG -----\r\n\t\t$(&quot;#dialog-confirm&quot;).html(\r\n\t\t\t&quot;&lt;p&gt;&quot; + $(this).attr(&quot;message&quot;) + &quot;&lt;\/p&gt;&quot; +\r\n\t\t\t&quot;&lt;p&gt;&quot; + &quot;&lt;textarea id=&#39;text_area_1&#39; style=&#39;width:100%; height:100%; resize:none; outline:none; box-sizing:border-box; -moz-box-sizing:border-box; -webkit-box-sizing:border-box; padding: 10px;&#39;&gt;The default text&lt;\/textarea&gt;&quot; + &quot;&lt;\/p&gt;&quot;\r\n\t\t);\r\n\t\t\r\n\t\t\/\/----- MAKE THE TEXTAREA FILL THE AVAILABLE SPACE IF THE DIALOG IS RESIZED -----\r\n\t\tvar d = $(&quot;#dialog-confirm&quot;).dialog({resizable:true});\r\n\t\td.bind(&quot;dialogresize&quot;, function(event, ui)\r\n\t\t{\r\n\t\t\t\tvar width = ui.size.width;\r\n\t\t\t\tvar height = ui.size.height;\r\n\t\t\t\t$(&#39;textarea#text_area_1&#39;).css(&#39;width&#39;, width - 50);\r\n\t\t\t\t$(&#39;textarea#text_area_1&#39;).css(&#39;height&#39;, height - 220);\r\n\t\t});\r\n\t\t\r\n\t\t\r\n\t\t\/\/----- ADD THE BUTTONS -----\r\n\t\t$( &quot;#dialog-confirm&quot; ).dialog(\r\n\t\t{\r\n\t\t\tresizable: true,\r\n\t\t\tmodal: true,\r\n\t\t\tbuttons:\r\n\t\t\t{\r\n\t\t\t\t&quot;OK&quot;: function()\r\n\t\t\t\t{\r\n\t\t\t\t\t\/\/----- OK -----\r\n\t\t\t\t\t\r\n\t\t\t\t\t\/\/Disable the dialog (if the next step takes a while to complete this stops the user being able to press a button again)\r\n\t\t\t\t\t$( this ).dialog( &quot;disable&quot; );\r\n\t\t\t\t\t\r\n\t\t\t\t\tvar new_text = escape($(&#39;textarea#text_area_1&#39;).val());    \/\/escape special characters\r\n\t\t\t\t\t\/\/alert( new_text );\r\n\t\t\t\t\t\r\n\t\t\t\t\t\/\/POST TO THE PHP PAGE\r\n\t\t\t\t\t$.post(&quot;some_page.php&quot;,\t\t\t\t\t\t\t\t\t\t\t\t\t\/\/Page to post to\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\/\/Data sent with the post request\r\n\t\t\t\t\t\t\taction: \"my_action_name\",\r\n\t\t\t\t\t\t\tid: usage_id,\r\n\t\t\t\t\t\t\ttext_field: new_text\r\n\t\t\t\t\t\t}, \t\r\n\t\t\t\t\t  function(data) {\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\/\/Callback function that is executed if the request succeeds - success(data, textStatus, jqXHR)\r\n\t\t\t\t\t\t\t$( &quot;#dialog-confirm&quot; ).dialog( &quot;close&quot; );\t\t\/\/Close the dialog box\r\n\t\t\t\t\t\t\talert( data );\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\/\/Display message echo&#39;d by the php file\r\n\t\t\t\t\t\t\thistory.go(-1);\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\/\/Go back to previous page\r\n\t\t\t\t\t   });\r\n\r\n\t\t\t\t\t\t \r\n\t\t\t\t\t$( this ).dialog( &quot;close&quot; );\r\n\t\t\t\t\twindow.location.reload()\r\n\t\t\t\t\t\/\/window.location = &quot;some_page.php&quot;;\r\n\t\t\t\t},\r\n\t\t\t\tCancel: function()\r\n\t\t\t\t{\r\n\t\t\t\t\t\/\/----- CANCEL -----\r\n\t\t\t\t\t$( this ).dialog( &quot;close&quot; );\r\n\t\t\t\t}\r\n\t\t\t},\r\n\t\t\ttitle: $(this).attr(&quot;title&quot;)\r\n\t\t});\r\n\t\t\r\n\t\t\r\n\t\treturn false;\r\n\t});\r\n&lt;\/script&gt;\r\n<\/code><\/pre>\n<h5>\nBody<br \/>\n<\/h5>\n<pre>\r\n<code>\r\n&lt;!-- div element used for confirmation and other dialogs --&gt;\r\n&lt;div id=&quot;dialog-confirm&quot; style=&quot;display:none;&quot;&gt;&lt;\/div&gt;\r\n&lt;!-- --&gt;\r\n\r\n&lt;a href=&quot;javascript:void(0)&quot; class=&quot;our_jquery_dialog&quot; title=&quot;The Title&quot;  message=&quot;A message&quot; usage_id=&quot;12345&quot;&gt;Open The Dialog&lt;\/a&gt;\r\n\r\n<\/code><\/pre>\n<h5>\nThe PHP File<br \/>\n<\/h5>\n<pre>\r\n<code>\r\n\r\n&lt;?php\r\n\t\r\n\tif(isset($_POST['action']))\r\n\t{\r\n\t\t$action = $_POST['action'];\r\n\t\tif($action == &#39;my_action_name&#39;)\r\n\t\t{\r\n\r\n\r\n\t\t}\r\n\r\n\t\techo &quot;Video deleted!&quot;;\r\n\r\n\t}\r\n\r\n\r\n?&gt;\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The HTML Head &lt;!&#8211; JQUERY UI &#8211;&gt; &lt;script src=&quot;https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.7.2\/jquery.min.js&quot; type=&quot;text\/javascript&quot;&gt;&lt;\/script&gt; &lt;!&#8211;Should be first script imported\/first script on the page&#8211;&gt; &lt;link rel=&quot;stylesheet&quot; href=&quot;http:\/\/ajax.googleapis.com\/ajax\/libs\/jqueryui\/1.8.9\/themes\/smoothness\/jquery-ui.css&quot; type=&quot;text\/css&quot; media=&quot;all&quot; \/&gt; &lt;script src=&quot;http:\/\/ajax.googleapis.com\/ajax\/libs\/jqueryui\/1.8.9\/jquery-ui.min.js&quot; type=&quot;text\/javascript&quot;&gt;&lt;\/script&gt; &lt;script type=&quot;text\/javascript&quot;&gt; \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- \/\/&#8212;&#8211; OUR JQUERY ENTER TEXT DIALOG &#8212;&#8211; \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- $(&quot;.our_jquery_dialog&quot;).live(&#39;click&#39;, function(e) { e.preventDefault(); \/\/&#8212;&#8211; OPTIONAL GET SPECIAL VALUES INCLUDED IN THE LINK &#8212;&#8211; var usage_id [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[131],"tags":[],"class_list":["post-1531","post","type-post","status-publish","format-standard","hentry","category-examples-dialogs"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/1531","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/comments?post=1531"}],"version-history":[{"count":4,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/1531\/revisions"}],"predecessor-version":[{"id":1536,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/posts\/1531\/revisions\/1536"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/media?parent=1531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/categories?post=1531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/javascript\/wp-json\/wp\/v2\/tags?post=1531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}