简体   繁体   中英

how do you call a javascript function within a method

I am working with Zendframework 1 .

On my view page, I used a JavaScript function * (JavaScript base64 encoder) *to encode some values: the function encrypts data that is transferred from one application to another.

I then want to send those value via a form to a method held within my controller. All of this should, in theory work fine.

My problem is this: once the value is received within my controller, I then need to decode it. So, I obviously need to attach a JavaScript function within my method that will enable me to then decode the information received.

Perhaps it might be easier if I show you what I am trying to achieve.

The form values with the enclosed values

<form action="#" method="post">

 <textarea name="txtstr" id="txtstr" cols="26" rows="5" Value="dGhlIGVuY2xvc2VkIHZhbHVlcyA="  ></textarea> 
<submit id="btnencode64">Encode</button><br/><br/>
</form>

The script for encoding the values

<script src="<?= $this->baseUrl() ?>/js/baseSixtyFourEncoder.js" type="text/javascript"></script>

The method within a controller

 public function ppAction()
 {
  $text = base64_decode($this->getRequest()->getParam('txtstr'));
 }

The issue now really is that I need to be able to use the JavaScript function once the form is received at the ppAction().

Is it possible to use the JavaScript function in this way. I realise that PHP and JavaScript cannot really be used at the same time. But is it possible to use JavaScript in this contact?

You cannot use a JS function in your PHP. PHP (server side scripting) is used to generate the page while Javascript (client side scripting) is used for the interactions within the page.

The following site tries to explain it a little bit more in details: http://wiki.answers.com/Q/What_are_client_side_and_server_side_scripting

You might also want to check this SO post for details about base64 en/de coding: How can you encode a string to Base64 in JavaScript?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM