Welcome visitor
* Login
* Register
It is currently March 18th, 2019, 3:25 pm
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Server Side » PHP



Post new topic Reply to topic  [ 2 posts ] 
Author Message
  help a newbie to understand the logic behind this
PostPosted: March 6th, 2009, 8:41 pm 
User avatar

Posts: 27
Hi, i have this script i found on some site:
<?php
if (is_array($_POST['options'])) {
foreach ($_POST['options'] as $option) {
echo $option.'<br />';
} }?>

<form action="evaluate.php" method="post" name="form">
<select  multiple name="options[]" size="5">
<option value="Cereal">Cereal
<option value="Juice">Juice
<option value="Bread">Bread
</select>
<input type="submit">
</form>
It works well and i've seen something very similar used to evaluate checkboxes, but how? whats the logic behind that? I think is better if you teach me how to fish instead of only give me the fish, thanks :D .


Top
 Profile  
 
  Re: help a newbie to understand the logic
PostPosted: March 6th, 2009, 9:03 pm 
User avatar

Posts: 61
clark_nt wrote:
<html><!--the form is going to be sent via POST to evaluate.php-->
<form action="evaluate.php" method="post" name="form">
<!--user can select more than one option and up to 5 items are going to be shown at a time-->
<!--each SELECTED option will be stored on an array called 'options' inside the $_POST array-->
<select  multiple name="options[]" size="5">
<!--each option value will be stored on the array 'options' ONLY if its selected-->
<!--these are called successful controls-->
<option value="Cereal">Cereal
<option value="Juice">Juice
<option value="Bread">Bread
</select>
<input type="submit">
</form></html>
<?php
//this line is to make sure that the array 'options' exist on the array '$_POST'
//this is used to avoid errors
if (is_array($_POST['options'])) {
//now this loop is going to send -one at a time- the values of the array 'options' to a variable called $option
//note that the $option value will change each cycle
foreach ($_POST['options'] as $option) {
echo $option.'<br />';
} }?>

was that your question? cheers ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

FORUMS » Server Side » PHP


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron