CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2004
    Location
    Mauritius Island
    Posts
    154

    XSLT,XML and PHP

    Firstly, here is my XML file:
    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <?xml-stylesheet type="text/xsl" href="sound.xsl"?>
    <sound>
    <sample>
    <title>sample1</title>
    <url>http://www.example.com/sample1.mp3</url>
    </sample>
    <sample>
    <title>sample2</title>
    <url>http://www.example.com/sample2.mp3</url>
    </sample>
    </sound>
    My XSLT:
    Code:
    <?xml version="1.0" encoding="iso-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <html>
    <head>
    <script type="text/javascript">
    
    function Listen() 
    {
    	var x;
    	var width  = 500;
    	var height = 350;
    	var left   = (screen.width  - width)/2;
    	var top    = (screen.height - height)/2;
    	var params = 'width='+width+', height='+height;
    	params += ', top='+top+', left='+left;
    	params += ', directories=no';
    	params += ', location=no';
    	params += ', menubar=no';
    	params += ', resizable=no';
    	params += ', scrollbars=no';
    	params += ', status=no';
    	params += ', toolbar=no';
    	x=document.forms[0].sel_Sounds.value; //Modify this part
    	url="Listen.php?ID="+x;
    	newwin=window.open(url,'Listen', params);
    	if (window.focus) 
    	{
    		newwin.focus()
    	}
    	return false;
    }
    </script>
    </head>
    <body>
    <form>
    <table border="0" align="center">
    <tr>
    <td>
    <select id="sel_Sounds">
    <xsl:for-each select="sound/sample">
    <option>
    <xsl:attribute name="value"><xsl:value-of select="url"/></xsl:attribute>
    <xsl:value-of select="title"/>
    </option>
    </xsl:for-each>
    </select>
    </td>
    </tr>
    <tr align="center">
    <td>
    <input type="button" value="Listen" onClick="Listen();"/>
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>
    I need to pass the value of the combo box to the Listen.php file. How do I access that value in the combo box?

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: XSLT,XML and PHP

    Any element that is to be processed by a form must have a name attribute. So give it a name, and then you can access it in the PHP page by using $_GET['element_name'] or $_POST['element_name'].
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Oct 2004
    Location
    Mauritius Island
    Posts
    154

    Re: XSLT,XML and PHP

    I get the following error:

    Notice: Undefined index: sel_Sounds in c:\program files\easyphp1-8\www\test\capture.php on line 10

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP grab value from combo box

    You haven't mentioned anything about that file before. Undefined index means that you are attempting to access an index within an array that does not exist. Double check your array.

    And this has nothing to do with XML.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP grab value from combo box

    [ moved ]
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  6. #6
    Join Date
    Oct 2004
    Location
    Mauritius Island
    Posts
    154

    Re: PHP grab value from combo box

    Can anyone help? Will it work if the XML and XSLT are modified?

  7. #7
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP grab value from combo box

    How can anyone help if you aren't making any sense, nor posting any code. Did you check for the array index as I already mentioned?

    Quote Originally Posted by girish_mu
    Will it work if the XML and XSLT are modified?
    Why would server-side code accessing a drop down change by XML unless you were filling the drop down with the XML?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  8. #8
    Join Date
    Oct 2004
    Location
    Mauritius Island
    Posts
    154

    Re: PHP grab value from combo box

    I had tried capturing the data from the combo by submitting the form to a page called capture.php and I used the following piece of code:
    Code:
    $captured_data=$_REQUEST['sel_Sounds'];
    And I got the error mentioned in a previous post. Have you tried the XML and XSLT? The combo is being filled with data from the XML file.

  9. #9
    Join Date
    Oct 2004
    Location
    Mauritius Island
    Posts
    154

    Talking Topic Closed

    I have found the error and it's working fine now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured