I want to send some data from ClassA
to ClassB
. So what I did is I create a hidden form in my ClassA
view page and post it to ClassB
.
<form id="invisible_form" action="classB" method="post" target="_blank"> <input id="post_to_chatroom" name="hiddenform" type="hidden" value="default"> </form>
Then from the js part
let recid = $(this).attr('data-recid'); let chatid = $(this).attr('data-chatid'); $('#post_to_chatroom').attr({ 'post_recid' : recid, 'post_chatid': chatid }); $('#invisible_form').submit();
But then I dont know how can I get the post data from ClassA
. I have tried getting the data from $_POST
in the php controller but it didnt work.
ClassB
controller
$t1 = isset($_POST['post_recid']) ? $_POST['post_recid'] : 'null'; $t2 = isset($_POST['post_chatid']) ? $_POST['post_chatid'] : 'null'; $jscript = "var postRecid =".$t1.";"; $jscript .= "var postChatid =".$t2.";";
but what I get is all null
value. So how can I get the post data value from class A?
Advertisement
Answer
With post data you can only send value attribute. You can add another two hidden fields.
<input name="post_recid" type="hidden" value="Your value"> <input name="post_chatid" type="hidden" value="Your value">
Or you can use jquery post to send data without submission.