dongtang3155 2011-03-31 13:10
浏览 33
已采纳

奇怪的JavaScript,PHP和Google Maps行为

I am breaking my brain in this situation :)

I have a form:

<form method="post" action="">
   <input type="hidden" name="entered_markers"
   value="<script type='text/javascript'> document.getElementById('rout_markers').value; </script>" />
 <input type="submit" value="Enter the trees you saw!" />
</p>
</form>

As you can see, the entered_markers tries to pass some JavaScript variables.

When I process the request, I do this

$chosen_markers = $_POST['entered_markers'];

Then the strange part :)

if ( empty ($chosen_markers) || !isset($chosen_markers) )  {
      $errors[] = 'Please click on the map to select spots where you spotted these tree. Markers: '.$chosen_markers;
} else {
   // Set something to signify that things are ok
}

And I always have the result that the validation thought the input was not empty, but when I tried to use that variable $rout_markers it just has nothing in it.

Where am I going wrong here? Isn't it sort of a strange thing that is happening? :)

  • 写回答

4条回答 默认 最新

  • douchangmian0305 2011-03-31 19:23
    关注

    Try it by creating a JavaScript function within your head and pass the form as the parameter to parse it's input fields. I went on and created a dummy text field name "rout_markers" and gave it a value of 300. So, on your PHP side if you look for $_POST['entered_markers'] it would echo out to be 300 if you use the example below:

    <html>
    <head>
    <script type='text/javascript'>
        function submitCoor(form){
            form['entered_markers'].value = document.getElementById('rout_markers').value;
        }
        </script>
    </head>
    <body>
    <input type='text' value='300' id='rout_markers' />
    <form method="post" action="test.php" onsubmit="submitCoor(this)">
        <input type="hidden" name="entered_markers"
        value="" />
        <input type="submit" value="Enter the trees you saw!" />
    </form>
    </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献