PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 19, 2022

[FIXED] how to use javascript to invoke the value of an html special data attribute and pass to php array in yii 1.1.14?

 March 19, 2022     html, javascript, jquery, php, yii     No comments   

Issue

I have an anchor link where the data-url has a value of a yii create url like this

<a href="#" id="download-button" data-url="<?php echo Yii::app()->createUrl('controllerName/actionName',array('var1'=>'var1_value', 'var2' => 'var2_value', 'var3' => '?')); ?>" data-chosen-type="">CLICK ME</a>

so the situation is like this, you see the data-chosen-type="" attribute?, the value is actually being set by a javascript. Now what I want to happen is, grab the value of data-chosen-type attribute and place it to 'var3' value, within the array inside that createUrl thing. So the output should be like this

 <a href="#" id="download-button" data-url="<?php echo Yii::app()->createUrl('controllerName/actionName',array('var1'=>'var1_value', 'var2' => 'var2_value', 'var3' => 'value of data-chosen-type')); ?>" data-chosen-type="">CLICK ME</a>

is that possible to do? I tried doing this

'var3' => "js:$('#download-button').attr('data-chosen-type')"

it didn't work, but in a view file especially in CGridView, putting javascript in a value of a key pair does work...how come in createUrl I wasn't able to do the same thing? am I doing it wrongly?


Solution

No, that is not possible, because PHP is long done before anything JavaScripty happens on the client.

If you can not determine the value on the server-side at all - then make an AJAX request to the server, so that you can call the createUrl method there with the correct parameters, and then set the link data-url attribute with the returned URL.



Answered By - CBroe
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing