mercredi 15 avril 2015

MVC Sending Values to Form

I have been making a site to learn about MVC, I am trying to add a function to the update option. At the moment I have two buttons on each row (one to delete and one to update), when the update button is pressed a form to update the row appears on the right of the screen.


I am trying to pre-populate the form when the user presses the update the button but I dont know how to do that within an MVC. Should I create a function that does this or should I have some PHP at the top of the form to pre-populate?


Any help or advice will be great


Update Form to be pre-populated



<h2>Update Item!</h2>
<h4>Fill in the form to update an entry.</h4>
<form action="index.php" method="post">
<fieldset>
<input id='action' type='hidden' name='action' value='updateItem' />
<p>
<label for="fTitle">Title</label> <input type="text"
id="fTitle" name="fTitle" placeholder="title"
maxlength="25" required />
</p>
<p>
<label for="fPrice">Price</label> <input type="text"
id="fPrice" name="fPrice" placeholder="price"
maxlength="25" required />
</p>
<p>
<label for="fDescription">Description</label> <input type="text"
id="fDescription" name="fDescription" placeholder="description"
maxlength="500" required />
</p>

<p>
<div class="form-group">
<div class="controls">
<button type="submit" class="btn btn-success">Update</button>
</div>
</div>
</p>
</fieldset>
</form>


Update button in the View receiving the row ID for the button



$update = file_get_contents( "templates/updateButton.php");
$HTMLItemList = "";
foreach ( $this->model->itemList as $row )
$HTMLItemList .= "<li><strong>" . $row ["title"] . ": </strong>" . "€" .$row ["price"] . "<blockquote>" .
$row ["description"] . " " . str_replace("value2replace", $row['id'], $delete) .
str_replace("value2replace", $row['id'], $update) . "</blockquote></li>";


Update Button



<form action="index.php" method="post">
<fieldset>
<input id='action' type='hidden' name='action' value='updateStart' />
<div class="form-group">
<div class="controls">
<input type="hidden" id="fId" name="fId" value="value2replace">
<input type="submit" class="btn btn-success" value="Update" />
</div>
</div>
</fieldset>
</form>

Aucun commentaire:

Enregistrer un commentaire