PHP Grab data element

Is there a way to grab the data element from a select menu?

<?php if(isset($_POST data="state)) { do something}
<html>
<option name="bike_state" data-state='.$row->state.'" class="option-center" value="'.$row->id.'" >'.$row->state.'</option>
</html>

Open in new window

LVL 7
rgranlundAsked:
Who is Participating?
 
Dave BaldwinFixer of ProblemsCommented:
That doesn't make any sense besides being too incomplete to be meaningful.  That is not what I just showed you to create the 'if(isset...' statement.  You must identify the $_POST item you want by using an 'index' like $_POST['item'].
0
 
Ray PaseurCommented:
http://iconoun.com/demo/temp_rgranlund.php

<?php // demo/temp_rgranlund.php
/**
 * See http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28629555.html
 *
 * Process HTML Select Options in PHP
 *
 */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);

// IF THERE HAS BEEN A POST-METHOD REQUEST
if (!empty($_POST['thing']))
{
    echo "THE SELECTED OPTION IS: " . $_POST['thing'];
}

// CREATE AN HTML FORM WITH A SELECT CONTROL
$form = <<<ENDFORM
<form method="post">
<select name="thing">
<option value="">Please Choose</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
<input type="submit" />
</form>
ENDFORM;

echo $form;

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.