I am working on Magento project.There I have a controller which is a php file.I want to write a JavaScript function inside that php file.
This is the function which results in the error,
public function verifyPinAction()
{
$data = $this->getRequest()->getPost();
echo "<script type='text/javascript'>
var datastring=<?php echo $data['pin'];?>;
$.ajax({
type: 'POST',
url: 'http://xxxxx.com/xxxxxx/ErrorProcessing1.php',
data : datastring,
//dataType: 'json',
success: function(html) {
//alert(html);
if(html=='wrong text entered')
{
<?php Mage::getSingleton('core/session')->addError('Invalid Pin Number');
$this->_redirect('enterpintoverify'); ?>
}
else{
<?php Mage::getSingleton('core/session')->addSuccess('Your Email is verified');
$this->_redirect('enterpintoverify');?>
}
}
});
</script>
";
}
It gives the following error
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /home/xxxxx/public_html/newtradesdev/app/code/local/Customer/Register/controllers/IndexController.php on line 65
Line 65 refers to
var datastring=<?php echo $data['pin'];?>;
Can someone tell me where have I gone wrong?
I have used xxxx marks beacause I am working on hosted site.Please skip the urls.
3
Answers
Change your echo to this instead:
This presents more readable code and will not cause any errors either.
Try using concatenate php code in your echo
It may happen due to parse error. Try concatenation for PHP Code.