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 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振