简体   繁体   English

HTML Imagemap作为表单提交

[英]HTML Imagemap As Form Submit

I am currently trying to create a simple php front-end for a mysql database hosted online. 我目前正在尝试为在线托管的mysql数据库创建一个简单的php前端。

The project I'm working on will take a grid layout of desks in an office building and turn them into an image map. 我正在进行的项目将采用办公楼中办公桌的网格布局,并将其转换为图像映射。 From there, depending on which seat is clicked on, it will pull information from the MySQL database, populate the fields of a form, and allow for edits if necessary. 从那里,根据点击的座位,它将从MySQL数据库中提取信息,填充表单的字段,并在必要时允许编辑。

I have a few files, listed below with their functions: 我有几个文件,下面列出了它们的功能:

locator.php - The 'homepage,' which holds the imagemap and is where the seat number variable will be coming from locator.php - '主页',它包含imagemap,是座位号变量的来源

form.php - The form that the data will populate, depending on the seat number passed from locator.php (Right now, this is just a basic HTML form I plan on completing later) form.php - 数据将填充的表单,具体取决于从locator.php传递的席位号(现在,这只是我计划稍后完成的基本HTML表单)

I've seen this done across the net with a regular form, but apparently an imagemap makes things a little trickier. 我已经看到这是通过常规形式在网上完成的,但显然图像映射使事情变得有点棘手。 I tried creating an onClick() event that takes the seat number that was clicked on and passes it into a javascript function, but from there I'm froze up as to how to continue on to the next page with that variable. 我尝试创建一个onClick()事件,该事件获取被点击的座位号并将其传递给javascript函数,但是从那里我已经冻结了如何继续使用该变量到下一页。

I feel like I have several ideas only partially implemented in my code, and I've hit a wall. 我觉得我的代码中只有部分实现了几个想法,而且我已经碰壁了。 Any ideas would be greatly appreciated. 任何想法将不胜感激。

locator.php: locator.php:

<img src="map.jpg" usemap="#disp_map">
<form name="formmap" action="form.html" method="post">
    <map name="disp_map">
        <area name="area_159" shape="rect" coords="11,261,58,308" href='#' onClick="submitform(159)" alt="#159">
        <area name="area_160" shape="rect" coords="11,311,58,358" href='#' onClick="submitform(160)" alt="#160">
    </map>
</form>

<br>
<hr>

<?php
$dbhost = "<<removedforprivacy>>";
$dbname = "<<removedforprivacy>>";
$dbuser = "<<removedforprivacy>>";
$dbpass = "<<removedforprivacy>>";

try{
    $conn = mysql_connect($dbhost,$dbuser,$dbpass);
    $db = mysql_select_db($dbname, $conn);
    echo '<img src="check.jpg" alt="Database Connection Made">' . 'Connection to the server was successfully made.<br>';
}catch(Exception $e){
    echo 'Exception!: ' . $e->getMessage() . '<br>';
}
?>

<script language="javascript" type="text/javascript">
function submitform(jack) {
    window.alert("Data will be displayed for jack #"+ jack +".");
    document.formmap.submit();
}
</script>

Consider the following snippets: 请考虑以下代码段:

<form name="formmap" action="form.html" method="POST">
    <input type='hidden' id='seatNumber'/>
</form>

function submitform(jack) {
    window.alert("Data will be displayed for jack #"+ jack +".");
    document.getElementById('seatNumber').value = jack;
    document.formmap.submit();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM