adding new feature to ImageBlock, need some help with radio buttons

gmoniey

Joined: 2005-11-01
Posts: 19
Posted: Wed, 2007-12-26 22:23

Hi,

I plan on submitting a patch to extend the link feature of Image Block, and I'm having a bit of trouble with radio buttons for the ImageBlockSiteAdmin.tpl file.

Basically, I have several radio buttons, and which define the behavior of the link. I have 1 radio button which has a text box attached to it, and when that button is selected, the value in the text box is used. However, my implementation doesnt work that way, and it seems that if there is text in the text box, the link value is automatically set to that, whether the associated radio button is selected or not.

here is a excerpt of the code:

 <input type="radio" id="radioAlbum" name="{g->formVar var="form[link]"}" value="album" {if $form.link == 'album'}checked="checked"{/if}/>
  <label for="radioAlbum">
    {g->text text="Album"}
  </label>
  <br/>

  <input type="radio" id="radioCustom" name="{g->formVar var="form[link]"}" value="" {if $form.link != 'album' && $form.link != '' && $form.link != 'none'}checked="checked"{/if}/>
  <label for="radioCustom">
    {g->text text="Custom Link:   "}
  </label>
      <input type="text" size="30" name="{g->formVar var="form[link]"}" {if $form.link != 'album' && $form.link != '' && $form.link != 'none'}value="{$form.link}"{/if}	id="radioCustomLink" />
  <br/>

  <input type="radio" id="radioNone" name="{g->formVar var="form[link]"}" value="none" {if $form.link == 'none'}checked="checked"{/if}/>
  <label for="radioNone">
    {g->text text="None"}
  </label>

So how can I make it so that the link value is only set to the text if the associated radio button is also selected?

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Thu, 2007-12-27 21:15

The problem is that you have two controls (a radio button set and a text box) that have the same HTML name attribute. Browsers will send back a response for each set, so the order in which they're coming back and getting processed causes one to override the other.

Try changing the name of the text input to something other than form[link] and see what you get back.