1779 Posts in 582 Topics by 556 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2861 Views |
-
HiddenField dont makes "value"

22 January 2009 at 5:16am Last edited: 22 January 2009 5:18am
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!!
-
Re: HiddenField dont makes "value"

22 January 2009 at 5:31am
okay now it works!
I added the line "title = "test," and now it works!!
new HiddenField (
$name = "FromID",
$title= "test",
$value = "3"
) -
Re: HiddenField dont makes "value"

22 January 2009 at 5:58am Last edited: 22 January 2009 5:58am
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.
-
Re: HiddenField dont makes "value"

22 January 2009 at 9:20pm
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 !
-
Re: HiddenField dont makes "value"

5 February 2009 at 2:49pm
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?
-
Re: HiddenField dont makes "value"

19 March 2012 at 6:41am
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
| 2861 Views | ||
|
Page:
1
|
Go to Top |


