Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

Creating a multi input form


Reply


453 Views

Avatar
cumquat

Community Member, 198 Posts

17 February 2014 at 12:50am

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