Simple one i think - Default value in input field

Permalink
Hi,

I am editing a block currently and want to add a default value to each of my fields (its in the mailchimp add on and its simply 'name' and 'email' i want to add in their respective fields..

This is the code

<form action="<?php echo $this->action('signmeup')?>" method="post" id="mail_form">
      <?php echo t('Your Name')?><br/>
      <?php echo $fm->text('fullname',$fullname,array('size'=>'32'))?><br/>
      <?php echo t('Email')?><br/>
      <?php echo $fm->text('email',$email,array('size'=>'32'))?>
      <?php echo $fm->hidden('id',$list)?>


Where and or how would I make these fields show a default value?

thanks for looking :)

 
mkly replied on at Permalink Best Answer Reply
mkly
<form action="<?php echo $this->action('signmeup')?>" method="post" id="mail_form">
      <?php echo t('Your Name')?><br/>
     // here
      <?php echo $fm->text('fullname',t('Default Name'),array('size'=>'32'))?><br/>
      <?php echo t('Email')?><br/>
      <?php // here ?>
      <?php echo $fm->text('email',t('Default Email'),array('size'=>'32'))?>
      <?php echo $fm->hidden('id',$list)?>


One thing to keep in mind is that upon a validation error the user will get the default fields again instead of their previously typed in value. Not sure if that matters.

Also, the c5 site docs for forms is actually pretty good.

http://www.concrete5.org/documentation/developers/forms/standard-wi...
obaluba replied on at Permalink Reply
Thanks Mkly, that seems to do the trick, how can I set it so when I click on the field the default value disappears?

thanks
mkly replied on at Permalink Reply
mkly
That last array and add any html attributes you would like to add. So you could do this with the onfocus attribute.
<?php echo $fm->text('fullname', t('Default Name'), array('size' => '32', 'onfocus' => 'if(this.value == "Default Name") { this.value = ""; }')); ?>