mardi 14 août 2018

how to handle checkbox data from another form

I am trying to post checkbox values when I click the image in another form, but not succeed.I found a sample and put it inside image POST. When I clicked the image, I want to post coordinates X and Y and checkbox values.I want to avoid submit button.

please help me

//this is image, ı am posting mouse click coordinates

$column_1 .= '
<form  action=""   method="post">
<input  type="image" 
alt="Finding coordinates of an image"  src="data:image/png;base64,' . 
$bytess . '" alt="Digg" width=150  height=200  border="0" name="foo" 
style="cursor:crosshair;"return false"; /></form>';




$tableHeader='<table width="100%">';
$tableFooter='</table>';    
$leftTable=$tableHeader;
$rightTable=$tableHeader;



// I am posting coordinates, also want to checkbox values, but not succeed.
if (isset($_POST['foo_x'])) 
{ 

$foo_x=$_POST['foo_x'];
$foo_y=$_POST['foo_y'];
echo "X=$foo_x, Y=$foo_y ";


if(isset($_POST['formSubmit'])) 
   {
    $aDoor = $_POST['formDoor'];

    if(isset($_POST['formWheelchair'])) 
    {
        echo("<p>You DO need wheelchair access.</p>\n");
    } 
    else 
    {
        echo("<p>You do NOT need wheelchair access.</p>\n");
    }

    if(empty($aDoor)) 
    {
        echo("<p>You didn't select any buildings.</p>\n");
    } 
    else 
    {
        $N = count($aDoor);

        echo("<p>You selected $N door(s): ");
        for($i=0; $i < $N; $i++)
        {
            echo($aDoor[$i] . " ");
        }
        echo("</p>");
    }

    //Checking whether a particular check box is selected
    //See the IsChecked() function below
    if(IsChecked('formDoor','A'))
    {
        echo ' A is checked. ';
    }
    if(IsChecked('formDoor','B'))
    {
        echo ' B is checked. ';
    }
    //and so on
    }


  }



echo "<table border='1'>
   <tr>
      <td valign=top >$column_1</td>

  </tr>
  </table>";



  echo "<tr>";



 echo "</table>";


  echo "<tr>";  



?>

  <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" 
 method="post">
 <p>
    Which buildings do you want access to?<br/>
    <input type="checkbox" name="formDoor[]" value="A" />Acorn Building<br 
   />
    <input type="checkbox" name="formDoor[]" value="B" />Brown Hall<br />
    <input type="checkbox" name="formDoor[]" value="C" />Carnegie Complex<br 
 />
    <input type="checkbox" name="formDoor[]" value="D" />Drake Commons<br />
    <input type="checkbox" name="formDoor[]" value="E" />Elliot House
   </p>
   <p>
    Do you need wheelchair access?
    <input type="checkbox" name="formWheelchair" value="Yes" />
    </p>
    <input type="submit" name="formSubmit" value="Submit" />
  </form>

  <p>
   <a href='http://www.html-form-guide.com/php-form/php-form- 
   checkbox.html'>Handling checkbox in a PHP form processor</a>
 </p>

 </body>
  </html>




Aucun commentaire:

Enregistrer un commentaire