Jump to:

3461 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Show DB entry with ID what is given with a form..

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

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

    Show DB entry with ID what is given with a form.. Link to this post

    hey guys, i need help

    when i create any form to many any stuff, i do this for example:

       function SpeicherSprache() {
          if(Member::currentUserID()) {
                $fieldset = new FieldSet(
                   new TextField(
                      $name = "Sprache",
                      $title = "Sprache",
                      $value = ""
                   ...
                   ...
                   ...
                   ...
                   new TextField(
                      $name = "Muttersprache",
                      $title = "Muttersprache",
                      $value = ""
                   )
                );
                
             $actions = new FieldSet(
                new FormAction('doSenden', 'Submit')
             );
             
             return new Form($this, 'SpeicherSprache', $fieldset, $actions);
          } else
             return false;
       }

       function doSenden($data, $form) {
          $submission = new SprachenObjekt();
          $form->saveInto($submission);
          $submission->write();
          
          Director::redirectBack();
       }

    and this works. "SprachenObjekt" is just a DataObjekt i created.

    soo.. now the User should have an DropdownField to choose one ob the many "SprachenObjekt" in the DB.
    hier code:

       function HoleSprache() {
          $myDoSet = DataObject::get("SprachenObjekt","");
          if($myDoSet){
             $map = $myDoSet->toDropDownMap('ID', 'Sprache');
             $map = str_replace($search = array('<', '>'), $replace = array('&lt;', '&gt;'), $map);
             
             $fieldset = new FieldSet(
                new DropdownField(
                   $name = "sprachen",
                   $title = "Sprache w&auml;hlen",
                   $source = $map,
                   $value = ""
                )
             );
          }

          $actions = new FieldSet(
             new FormAction('ZeigeSprache', 'Anzeigen')
          );
          
          return new Form($this, 'HoleSprache', $fieldset, $actions);
       }
       
       function ZeigeSprache() {
          if(!isset($_POST['sprachen']))
          $_POST['sprachen'] = 1;

          $sprache = new DataObjectSet();
          
          $result = DB::query("SELECT * FROM SprachenObjekt WHERE ID = '".$_POST['sprachen']."'");
                
          if($result) {
             foreach($result as $value) {
                $eintraege = array(
                               'ID' => $value['ID'],
                               'Sprache' => $value['Sprache'],
                               'Kaum' => $value['Kaum'],
                               'Mittel' => $value['Mittel'],
                               'Gut' => $value['Gut'],
                               'Muttersprache' => $value['Muttersprache']
                               );
                $sprache->push(new ArrayData($eintraege));
             }
          }
          return $sprache;
       }

    And this code is in my .SS file:

    $HoleSprache

    <% control ZeigeSprache %>
    $Sprache<br />
    $Kaum<br />
    $Mittel<br />
    $Gut<br />
    $Muttersprache<br />
    <% end_control %>

    Now when i enter into this page, the Data of DB entry with "ID = 1" is shown.
    And there is the DropdownField and the Button.. BUT when i click the button i just get a white page with the word "DataObjektSet".
    Okay, in other forms, there is a "RedirectBack()" in the called function.. so i dont know how to handle this problem.. :S

    THANKS FOR ANSWERS

    1119 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.