Reputation: 171
I am a bit at lost as my PHP knowledge is very basic to say the least, but I am learning on the fly.
In a Wordpress plugin, I have the following php function:
$pool->get_leagues( true );
which gives a an array of league values: the id number and the name of the league.
Then there is this function:
$pool = new Football_Pool_Pool;
$pool->update_league_for_user( get_current_user_id(), <<THIS IS WHERE SELECTED ID NUMBER GOES>> );
I need to create an HTML form that lists the available league names that the user on a page can select in either an dropdown form, with radio buttons or plain links, whatever is easiest for the example.
Then, when the user makes a choice and submits the values, the league value should be updated into the database as per the above function.
Here are my total newbe / dummy questions:
Help is much much appreciated!
Upvotes: 1
Views: 129
Reputation: 382
I think you have to create a whole new PHP file. Here the PHP code and the HTML are in a single PHP file.
<?php
if(!isset($_POST['submit'])){
//if the form has not been submitted yet, display the form
echo "<form name='myform' action='' method='POST'>";
//Get array of leagues
$leagues = $pool->get_leagues(true);
//Make a drop down
echo "<select name='league'>";
foreach($leagues as $league){
echo "<option>$league</option>";
}
echo "</select>";
echo "<input type='submit' name='submit' value='Submit'>";
echo "</form>";
}else{
//If the form has been submitted, run the PHP function to update database
$pool = new Football_Pool_Pool;
$pool->update_league_for_user(get_current_user_id(), $_POST['league']);
echo "Database updated!";
}
?>
Upvotes: 1