0

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?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
andreea115
  • 289
  • 1
  • 3
  • 14

1 Answers1

0

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?

Community
  • 1
  • 1
Joel Lord
  • 2,175
  • 1
  • 18
  • 25
  • hello Joellord. i am able to encode correctly. the only problem is the decoding part once the post is returned. the question then is this. can i use a php decoding script for my decoding. – andreea115 Jul 15 '13 at 15:07
  • You could always try the PHP decode function http://php.net/manual/fr/function.base64-decode.php – Joel Lord Jul 15 '13 at 16:11