Jump to content

include some jquery codes inside module's displayForm() function showing error


Recommended Posts

Hi,

 

I know this one is a basic question. But I don't know why I can't figure it out. I am doing a simple module in prestashop. I have a module name testmodule. In the testmodule.php I have all the php files inside. In that testmodule.php I want to use 3-4 lines of jquery code inside _displayForm() function. I am simply using that code like this

 

<script type="text/javascript">
 jQuery('input[name="file_upload"]').change(function(){
   if(jQuery(this).val() == 'yes'){
     jQuery('input[type="file"]').prop('multiple', true);
   }else{
       jQuery('input[type="file"]').prop('multiple', false);
   }
 });
</script>

 

but this one is showing error like Parse error: syntax error, unexpected '<' on line . So can someone kindly tell me how to solve this issue? Any help and suggestions will be really apprecable. Thanks

Link to comment
Share on other sites

use code with literal tags, remember to insert it into the .tpl file

not in .php !

 

{literal}
<script type="text/javascript">
 jQuery('input[name="file_upload"]').change(function(){
if(jQuery(this).val() == 'yes'){
  jQuery('input[type="file"]').prop('multiple', true);
}else{
	jQuery('input[type="file"]').prop('multiple', false);
}
 });
</script>
{/literal}

Link to comment
Share on other sites

use code with literal tags, remember to insert it into the .tpl file

not in .php !

 

{literal}
<script type="text/javascript">
 jQuery('input[name="file_upload"]').change(function(){
if(jQuery(this).val() == 'yes'){
  jQuery('input[type="file"]').prop('multiple', true);
}else{
	jQuery('input[type="file"]').prop('multiple', false);
}
 });
</script>
{/literal}

 

Yes but I want this piece of code to run in admin panel not in user site. So as I know that the admin panel shows the form so in _displayForm() function I have the form. In that form I want my jquery code to be executed.

Link to comment
Share on other sites

@vekia thanks for the reply. But can you tell me how to do this with some example codes.

My code is something like this lets say

 

 public function getContent() {
     $this->_html = '<h2>'.$this->displayName.'</h2>';

   if (Tools::isSubmit('submitUpdate')) {
     Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'tablename` SET `function_name`="'.$body_option.'",`height`="'.$height.'",`width`="'.$width.'"');

     $this->_displayForm();
     return $this->_html;
   }
 }



 private function _displayForm() {
   $this->_html .=  '
     <link rel="stylesheet" href="../modules/modulename/css/store_styles.css" />
     <script src="../modules/modulename/js/jquery-1.7.2.min.js" type="text/javascript"></script>';

     $this->_html .= '<input type="file" name="file" id="file"  multiple/>';

   $this->_html .= '
     <form method="post" action="'.$_SERVER['REQUEST_URI'].'" id="test">';

   $this->_html .= '<div class="clear"></div></div>
     <label>'.$this->l('Upload Image').' </label>
     <div class="margin-form">';
     $this->_html .= '<input type="file" name="file" id="file"  multiple/>';
     $this->_html .= '</div>';

       $this->_html .= '
       <div class="margin-form clear"><input type="submit" name="submitUpdate" value="'.$this->l('Save').'" class="button" /></div>
       </form>      
 }

 

So as per my requirement when I will click on checkbox then this piece of code should work.

<script type="text/javascript">
 jQuery('input[name="file"]').change(function(){
   if(jQuery(this).val() == 'yes'){
     jQuery('input[type="file"]').prop('multiple', true);
   }else{
       jQuery('input[type="file"]').prop('multiple', false);
   }
 });
</script>

 

an you show your module displayForm() function ?

everything depends on it

 

@vekia thanks for the reply. But can you tell me how to do this with some example codes.

My code is something like this lets say

 

 public function getContent() {
  $this->_html = '<h2>'.$this->displayName.'</h2>';

if (Tools::isSubmit('submitUpdate')) {
  Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'tablename` SET `function_name`="'.$body_option.'",`height`="'.$height.'",`width`="'.$width.'"');

  $this->_displayForm();
  return $this->_html;
}
 }



 private function _displayForm() {
$this->_html .=  '
  <link rel="stylesheet" href="../modules/modulename/css/store_styles.css" />
  <script src="../modules/modulename/js/jquery-1.7.2.min.js" type="text/javascript"></script>';

  $this->_html .= '<input type="file" name="file" id="file"  multiple/>';

$this->_html .= '
  <form method="post" action="'.$_SERVER['REQUEST_URI'].'" id="test">';

$this->_html .= '<div class="clear"></div></div>
  <label>'.$this->l('Upload Image').' </label>
  <div class="margin-form">';
  $this->_html .= '<input type="file" name="file" id="file"  multiple/>';
  $this->_html .= '</div>';

	$this->_html .= '
	<div class="margin-form clear"><input type="submit" name="submitUpdate" value="'.$this->l('Save').'" class="button" /></div>
	</form>	  
 }

 

So as per my requirement when I will click on checkbox then this piece of code should work.

<script type="text/javascript">
 jQuery('input[name="file"]').change(function(){
if(jQuery(this).val() == 'yes'){
  jQuery('input[type="file"]').prop('multiple', true);
}else{
	jQuery('input[type="file"]').prop('multiple', false);
}
 });
</script>

Link to comment
Share on other sites

×
×
  • Create New...