Jump to:

2012 Posts in 1438 Topics by 621 members

Form Questions

SilverStripe Forums » Form Questions » Creating a multi input form

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

Page: 1
Go to End
Author Topic: 394 Views
  • cumquat
    Avatar
    Community Member
    198 Posts

    Creating a multi input form Link to this post

    Wasnt sure what to put as the title of this post, i have a form that needs to contain the same field 4 or 5 times, its for logging in a runner at a checkpoint and rather than just adding one record at a time i'd like to be able to add 4 or 5. I have got this to work by creating my form in HTML then processing with silverstripe as normal but i wondered if there is a way to create the form using the normal silverstripe coding way. does this make sense? anyway here is my form and the function to process just wondered if anyone new how i could do this without adding the html to page and just add it to mu controller.

    <form id="signin" method="post" action="checkpoint/dosignin">
    <div class="large-5 medium-5 small-12 columns continuing">
    <h4 class="black">Continuing Checkpoint <% with getCheckpoint %>$Name<% end_with %></h4>
    <hr />
    <input type="number" placeholder="Runners Number" name="RunnerNumber[]" id="RunnerNumber" >
    <input type="number" placeholder="Runners Number" name="RunnerNumber[]" id="RunnerNumber" >
    <input type="number" placeholder="Runners Number" name="RunnerNumber[]" id="RunnerNumber" >
    <input type="number" placeholder="Runners Number" name="RunnerNumber[]" id="RunnerNumber" >
    <input type="hidden" name="CheckpointID" id="CheckpointID" value="<% with getCheckpoint %>$ID<% end_with %>"/>
    <input type="submit" name="submit" id="submit" class="small button success radius" value="Runner Check in"/>
    </div>
    </form>

    function dosignin(){
          $theID = $_POST["CheckpointID"];
          $in = date("Y-m-d H:i:s");
          for($i = 0; $i < 4; $i++)   {
             $RunnerNum   = $_POST["RunnerNumber"][$i];
             if($RunnerNum){
                $therunner = Runner::get()->filter(array('RaceNumber' => $RunnerNum))->first();
                $runID = $therunner->ID;
                $submission = new Checkin();
                $submission->CheckpointID = $theID;
                $submission->RunnerID = $runID;
                $submission->TheTime = $in;
                $submission->Status = 'yes';
                $submission ->write();
             }
          }
          Controller::curr()->redirectBack();
       }

    cheers
    mick

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