News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

having trouble with <a href + variables in XHTML

Started by Thunderace, July 04, 2005, 04:56:30 PM

Previous topic - Next topic

Thunderace

The below works but fails XHTML

echo '<input type="checkbox" name="c' . $i . '" value="<a href=' . $siteurl . '/index.php?&page=' . $file . ' alt=test>' . $file . '</a><p />">&nbsp;<input type="text" name="pos' . $i . '" size="1"><br />';

XHTML error is

Quotean attribute value specification must be an attribute value literal unless SHORTTAG YES is specified

I can see that the <a href and alt need "" but when I add them the code fails

Grudge

I'm confused, is the link supposed to be displayed in the text box?? Assuming it is the I would expect you need to put the tags as entities and not < or > - as otherwise the browser will try to render it (use &lt; and &gt;). If it's NOT supposed to be in the input box then you've done something very wrong with your HTML!
I'm only a half geek really...

Thunderace

#2
without variables it should look like this ..

<input type="checkbox" name="anyname" value="<a href="www.mysite.com">Mysite</a><p />" />
<input type="text" name="name" size="1" /><br />


I want to pass a full <a href as a variable, it works now just fails XHTML

Grudge

OK - Should be:

<input type="checkbox" name="anyname" value="&lt;a href=&quot;www.mysite.com&quot;&gt;Mysite&lt;/a&gt;&lt;p /&gt;" />


But you do realise that the "value" of a checkbox element is never shown? That is the value sent to whatever you script you are submitting to - or at least that's what I think (I'm no HTML expert). If you want that to be a label for the checkbox you should use the label tag.
I'm only a half geek really...

Thunderace

#4
Yes, this script finds a file and creates a link to it

2nd input is just a number to assign to each menu item for positioning.

while ($file = readdir($handle)) {
   if(!is_dir($file) && !is_link($file)) {
    $fileurl = urlencode($file);
      $filelist .= $file . '<input type="checkbox" name="c' . $i . '" value="<a href=' . $siteurl . '/index.php?&page=' . $file . '>' . $file . '</a><p />">&nbsp;<input type="text" name="pos' . $i . '" size="1"><br />';
      $i++;
   }
}

Grudge

Ah, I see. In that case the code should be:

while ($file = readdir($handle)) {
   if(!is_dir($file) && !is_link($file)) {
    $fileurl = urlencode($file);
      $filelist .= $file . '<input type="checkbox" name="c' . $i . '" value="&lt;a href=&quot;' . $siteurl . '/index.php?&page=' . $file . '&quot;&gt;' . $file . '&lt;/a&gt;&lt;p /&gt;">&nbsp;<input type="text" name="pos' . $i . '" size="1"><br />';
      $i++;
   }
}
I'm only a half geek really...


Advertisement: