Reputation: 803
I have a list of records in a table with a checkbox beside each one.
The user selects a number of records by ticking the checkbox and then selects an action from a drop down list of links.
<div class="button-group">
<button type="button" id="but1">Action</button>
<ul class="dropdown" id="dropdown-but1">
<li><a href="#">Update Attendees</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">One more action</a></li>
</ul>
</div>
An example of an action might be updating if a user attend an event.
if(isset($_POST['submit']))
{
foreach ($_POST['checkbox_mark'] as $value => $dummy) {
$option = isset($_POST['checkbox'][$value]) ? '1' : '0';
// Send the Data to the Model
$eventRegistrationModel->markAttended($value, $id, $option);
}
}
At the minute I have this working for a single submit button, but I would like the user to be able to choose from a list of options in a dropdown and then the appropriate action is called.
I can't seem to find an example of this, but I am maybe not searching for the correct term. Assuming I will need to use jquery for this.
I have found a way to do this using the form elements https://stackoverflow.com/a/17423522/1472203 but wondering if it is possible with text links.
Upvotes: 0
Views: 60
Reputation: 4063
Making submit buttons look like links
Then have as many different submit buttons as you'd like for each action and in the action file just check for the submission of the buttons:
<div class="button-group">
<button type="button" id="but1">Action</button>
<ul class="dropdown" id="dropdown-but1">
<li><input type="submit" name="update_attendees" value="Update Attendees" class="buttonThatLooksLikeALink"></li>
<li><input type="submit" name="another_action" value="Another action" class="buttonThatLooksLikeALink"></li>
<li><input type="submit" name="one_more_action" value="One more action" class="buttonThatLooksLikeALink"></li>
</ul>
</div>
Then in PHP:
<?php
if($_SERVER["REQUEST_METHOD"]==="POST")
{
if(isset($_POST["update_attendees"]))
{
# Update those attendees!
}
elseif(isset($_POST["another_action"]))
{
# Do that other action!
}
elseif(isset($_POST["one_more_action"]))
{
# Do the OTHER action
}
}
Upvotes: 1