Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » HiddenField dont makes "value"

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 4205 Views
  • SalvaStripe
    Avatar
    Community Member
    89 Posts

    HiddenField dont makes "value" Link to this post

    hey guys..

    i try to create a form, but the "HiddenField" dont makes a value.

    Page Type With Form Function

             $fieldset = new FieldSet(
                new TextField(
                   $name = "Title",
                   $title = "Betreff",
                   $value = "Betreff eingeben"
                ),
                new TextareaField(
                   $name = "Message",
                   $title = "Nachricht",
                   $rows = 8,
                   $cols = 3,
                   $value = "Nachricht eingeben"
                ),
                new OptionsetField(
                   $name = "ToID",
                   $title = "Alle Member",
                   $source = $map,
                   $value = $map[2]
                ),
                 new HiddenField (
                   $name = "FromID",
                   $value = "3"
                )
             );

    This is my fieldset.. the value from "Title" and "Message" is shown in Sourcecode..

    Browser Source Code

    <div id="Title" class="field text "><label class="left" for="Form_SendenForm_Title">Betreff</label><span class="middleColumn"><input class="text" type="text" id="Form_SendenForm_Title" name="Title" value="Betreff eingeben" /></span></div>
    <div id="Message" class="field textarea "><label class="left" for="Form_SendenForm_Message">Nachricht</label><span class="middleColumn"><textarea id="Form_SendenForm_Message" name="Message" rows="8" cols="3">Nachricht eingeben</textarea></span></div>

    But here look the HiddenField.. thereshould be a "3" in value.. bot nothing is there.

    Browser Source Code

    <input class="hidden" type="hidden" id="Form_SendenForm_FromID" name="FromID" value="" />

    in my "saphire/forms/HiddenField.php" is this line.. but its like the line in TextField.php and there is works..

    HiddenField.php

       function Field() {
          //if($this->name=="ShowChooseOwn")Debug::show($this->value);
          return "<input class=\"hidden\" type=\"hidden\" id=\"" . $this->id() . "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" />";
       }

    HEEEELP!!

  • SalvaStripe
    Avatar
    Community Member
    89 Posts

    Re: HiddenField dont makes "value" Link to this post

    okay now it works!

    I added the line "title = "test," and now it works!!

          new HiddenField (
                $name = "FromID",
                $title= "test",
                $value = "3"
             )

  • UncleCheese
    Avatar
    4085 Posts

    Re: HiddenField dont makes "value" Link to this post

    Yeah, that's one of the most annoying things about HiddenField. It requires a Title attribute by virtue of its inheritance.

    I'd skip the keyword arguments all together and just do:

    new HiddenField('Name','','Value');

    it's a lot cleaner.

  • SalvaStripe
    Avatar
    Community Member
    89 Posts

    Re: HiddenField dont makes "value" Link to this post

    yes it is. but my way is better to understand or to know exactly what is what..
    the SS dokumentations are not very exactly.

    http://doc.silverstripe.org/doku.php?id=hiddenfield

    new HiddenField (
    $name = "hidden"
    )

    wow.. very helpful

    http://doc.silverstripe.org/doku.php?id=recipes:simplesearch

           new HiddenField("action_results", "Go")

    this is from simple search.. does it work with only 2 statements or is this a bug in documentation?

    but i love SS and as long i can fix all my bugs.. its very good CMS of course !

  • svinkle
    Avatar
    Community Member
    16 Posts

    Re: HiddenField dont makes "value" Link to this post

    I'm experiencing something odd with this. Here's my code:

    static $db = array(
    'Category' => 'Text'
    );
    .
    .
    .
    function getCMSFields() {
    $fields = parent::getCMSFields();
          $fields->addFieldToTab('Root.Content.Main', new HiddenField('Category', '', 'Category 1'));

    return $fields;
    }

    This should set the value to "Category 1" in the form. When I view the source there is no value set. However, if I change the name parameter from "Category" to anything else, I can see that the value gets properly set. Doesn't the name parameter have to match that in the $db array for the value to get set in the database?

  • prawnstar
    Avatar
    Community Member
    116 Posts

    Re: HiddenField dont makes "value" Link to this post

    SS 2.4.6

    I know this questions is waaaay old, but if you're banging your head against it (like me) and are frustrated, try this.

    If this doesn't work (as it didn't for me either):

    public function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Content.Main', new HiddenField('Name','Title','Value'));
          return $fields;
    }

    Try setting the defaults as a static like this:

    static $defaults = array(
    'Name' => 'Value'
    );

    Solved my issue.

    Chris.b

    4205 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.