Search code examples
phpjquerysymfonysymfony3

Get data attribute value in Symfony controller


In my View, I have this hidden field

<input type="hidden" id="logoID" name="logoID" class="logoID" value="123">

I add additional data to it using data attribute via jQuery like this

$('.logoID').data('fileName', 'xyz.jpg')  
// adds data attribute to input element -> <input ... data-fileName='xyz.jpg' /> 

Now I need to retrieve this fileName inside my controller. I know I can get value of this hidden field by

$form['logoID']->getData();       // 123

But I also need the value of the data-attribute (fileName). How can I go about it? Any leads are much appreciated.


Solution

  • data-attributes are not available directly by the PHP scripts. You need to send that value using another hidden input or retrieve the value with Jquery later and post it as data using Ajax.