In this activity you will create a form and use it to pass data from one page to another.
form.php
<?php
include('header.php');
include('menu.php');
?>
<main>
<p>Choose your hero.</p>
<ol>
<li><a href="process_form.php?name=Loki">Loki</a></li>
<li><a href="process_form.php?name=Hulk">Hulk</a></li>
</ol>
</main>
<?php
include('footer.php');
?>
process_form.php
<?php
include('header.php');
include('menu.php');
?>
<main>
<p>You have chosen <?php echo $_GET['name']; ?></p>
</main>
<?php
include('footer.php');
?>
<main> tag.<form> tag has a parameter called action. This is where you want to send your data.action to 'process_form.php'.<form action="process_form.php">
<form> tags. <button type="submit" name="name" value="Loki"></button>
<button type="submit" name="name" value="Hulk"></button>
type to 'submit' means that when we click the button it will submit the form and send the data. Both buttons will do this.name is the parameter name to be sent. Submit buttons will often be named 'submit' and not contain data, but sometimes there will be two forms on a page (or sent to a page) and you need to know which one to process. We use that here to differentiate the selected heroes.value is the text that will appear on the button.<form> tag and add the following code. <ul>
<li>
</li>
</ul>
<li>
<label>Hero Name:</label>
<input type="text" name="name" size="30" maxlength="50" hint="Iron Man">
</li>
<label> tag.type="button" or type="submit", it is type="text" which is used for a simple text field, usually up to 100 characters or so.name that will inform 'process_form.php' what the value refers to.size sets the size of the input box to 30 characters and maxlength limits the length of characters that can be entered.hint. <li>
<label>Side:</label>
<input type="radio" name="side" value="Hero" checked="checked"> Hero<br>
<input type="radio" name="side" value="Villain"> Villain
</li>
<input> tag and, like buttons, they have a name and a value.value isn't displayed as it is on a button, because there's no room on a radio button. Instead, the value is the text we want to send to 'process_form.php'.<input depending on how we want the form to appear.checked attribute in the first input. This sets the default item if you want one. <li>
<label>First Appearance:</label>
<input type="number" name="year">
</li>
size and maxlength, but we'll look at better ways to manage this later.<select field. <li>
<label>Source of Power:</label>
<select name="power">
<option value="skill">Skill</option>
<option value="bio">Biological</option>
<option value="magic">Magic</option>
<option value="tech">Technology</option>
<option value="mutant">Mutant</option>
</select>
</li>
name for each option individually, we set it once in the <select> tag.value attribute, while the user sees the text between the <option> tags.<input type="submit" name="submit" value="Add Hero">
value associated with that option.