I feel like I'm overlooking something simple. I'm writing a module that provides a form, I need to display some info along with the form, and sometimes I want to make a bit of that info really stand out. $foo = $info1 . ' ' $info2 . ' ' . $info3; $form(['foo']=array( '#value' => $foo, ); Gives me: info1 info2 info3 OK, so far so good. Now if I set up $foo like this: if ($info3 == $X) { $foo = $info1 . ' ' $info2 . ' <font color:red>' . $info3 .'</font>'; } else { $foo = $info1 . ' ' $info2 . ' ' . $info3 } Then when foo == x I get: info3 info1 info2 Info3 is indeed red, but on the previous line. I've also tried inline style with <span style:...> and gotten the same result. I just need to make info3 stand out in certain cases. What am I missing here? Thanks, Carl
This sounds like a CSS styling issue, which has nothing to do with Drupal. The <font> tag is depreciated - you should stick with <span style=""> or <span class="important-form-text"> or similar. As to the actual problem, it will probably be a float: left/right, display:block, or similar problem - I'd use Firebug to quickly find it On 26 April 2011 20:32, Carl Jester <cjester@peladon.com> wrote:
I feel like I'm overlooking something simple. I'm writing a module that provides a form, I need to display some info along with the form, and sometimes I want to make a bit of that info really stand out.
$foo = $info1 . ' ' $info2 . ' ' . $info3; $form(['foo']=array( '#value' => $foo, );
Gives me: info1 info2 info3
OK, so far so good.
Now if I set up $foo like this: if ($info3 == $X) { $foo = $info1 . ' ' $info2 . ' <font color:red>' . $info3 .'</font>'; } else { $foo = $info1 . ' ' $info2 . ' ' . $info3 }
Then when foo == x I get: info3 info1 info2
Info3 is indeed red, but on the previous line. I've also tried inline style with <span style:...> and gotten the same result.
I just need to make info3 stand out in certain cases. What am I missing here?
Thanks, Carl
On Apr 26, 2011, at 4:07 PM, Frederik Grunta wrote:
This sounds like a CSS styling issue, which has nothing to do with Drupal.
It has to be at least a little related to Drupal. I get the same result under multiple themes. This was previously a chunk of php stuck in a page using the php filter, now I'm turning it into a proper Drupal module using the form api. So, it's got something to do with how the form is being assembled.
The <font> tag is depreciated - you should stick with <span style=""> or <span class="important-form-text"> or similar.
Yep. I just tried both to see if it would change the behavior. Got the same result either way in multiple themes. After I posted I realized I can to a _theme function to go with the _form function to help lay things out nicely without having to add .tpl files or other theme overhead to the project. I think it's time to go make friends with drupal_render(). Thanks, Carl
additional HTML (that are not form elements) are typically added to the $form array using using #prefix and/or #suffix instead of #value. $form['#prefix'] = 'some string to appear above the form'; $form['existing-element']['#prefix'] = 'this string will appear before the form element called existing-element'; $form['existing-element']['#suffix'] = 'this string will appear after the form element called existing-element'; James Wilson http://www.bluesparklabs.com On Tue, Apr 26, 2011 at 4:31 PM, Carl Jester <cjester@peladon.com> wrote:
After I posted I realized I can to a _theme function to go with the _form function to help lay things out nicely without having to add .tpl files or other theme overhead to the project. I think it's time to go make friends with drupal_render().
There is a proper form elemente for adding markup, which is '#type' => 'markup' . You place HTML inside the '#value'. Nothing wrong with this approach. #prefix and #suffix should be used to wrap elements with additional markup or add HTML that is related to an existing element. But that's not even the issue here, right? On Thu, Apr 28, 2011 at 12:56 PM, James Wilson <jrguitar21@gmail.com> wrote:
additional HTML (that are not form elements) are typically added to the $form array using using #prefix and/or #suffix instead of #value.
$form['#prefix'] = 'some string to appear above the form';
$form['existing-element']['#prefix'] = 'this string will appear before the form element called existing-element';
$form['existing-element']['#suffix'] = 'this string will appear after the form element called existing-element';
James Wilson http://www.bluesparklabs.com
On Tue, Apr 26, 2011 at 4:31 PM, Carl Jester <cjester@peladon.com> wrote:
After I posted I realized I can to a _theme function to go with the _form function to help lay things out nicely without having to add .tpl files or other theme overhead to the project. I think it's time to go make friends with drupal_render().
-- Franz http://ciudaddelpico.com Sent from my laptop
participants (4)
-
Carl Jester -
Franz Glauber -
Frederik Grunta -
James Wilson