Jump to content

Help with simple php form data


perficut

Recommended Posts

I am an amatuer programmer at best. Took some level 1 college programming on pascal, and basic years ago, so php coding looks familiar so the terminology makes sense but the syntax coding portion im still refreshing myself on.
Heres my situation;

Passing 3 variables from a basic html form  (street, city, zip) to map.php which echos the info back to the screen. I kept it simple since my main focus was using yahoos api map feature to embed a small map of the address.  I've inserted the code and it works fine if you hardcode the address into line 50. Figured if I could substitute the hardcoded address with the 3 variables recieved from the html form, i could get it to display a map of the data entered. Line 46 also contains an address but it doesnt seem to have any effect on the program as long as their is data in line 50. Cant figure out the proper syntax for passing the variable into line 50.  can you help?

Heres the map.html
<HTML><HEAD><TITLE>My Form - created with phpFormGenerator</TITLE></HEAD>
<BODY>
<font face='arial' size=2><b>All fields marked with a * are required:<br>
<form enctype='multipart/form-data' action='process.php' method='post'>
<table width='50%' border=0>
<tr><td> city</td>
<td>
<input type=text name='city' size=10></td></tr>
<tr><td> state</td>
<td>
<input type=text name='state' size=2></td></tr>
<tr><td> zip</td>
<td>
<input type=text name='zip' size=5></td></tr>
</table>
<input type='submit' value='Submit Form'> <input type=reset value='Clear Form'></form>
<br><br><br><a href='http://phpformgen.sourceforge.net'><img src='button.jpg' border=0></a>
</BODY></HTML>


Heres the map.php
1 <?php
2 include("global.inc.php");
3 $errors=0;
4 $error="The following errors occured while processing your form input.<ul>";
5 pt_register('POST','city');
6 pt_register('POST','state');
7 pt_register('POST','zip');
8 if($errors==1) echo $error;
9 else{
10 $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
11 $message="city: ".$city."
12 state: ".$state."
13 zip: ".$zip."
14 ";
15 $message = stripslashes($message);
16 mail("[email protected]","Form Submitted at your website",$message,"From: <$state>");
17 ?>


18 <!-- This is the content of the Thank you page, be careful while changing it -->

19 <h2>Thank you!</h2>

20 <table width=50%>
21 <tr><td>city: </td><td> <?php echo $city; ?> </td></tr>
22 <tr><td>state: </td><td> <?php echo $state; ?> </td></tr>
23 <tr><td>zip: </td><td> <?php echo $zip; ?> </td></tr>
24 </table>
25 <!-- Do not change anything below this line -->
26 <?php
27 }
28 ?>
29 <p><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
30  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
31 <html xmlns="http://www.w3.org/1999/xhtml">
32  <head>

33 <script type="text/javascript"
34 src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=mdsnowremoval"></script>
35 <style type="text/css">
36 #mapContainer {
37 height: 250px;
38 width: 250;
39 }
40 </style>
41 </head>
42 <body>
43 <div id="mapContainer"></div>

44 <script type="text/javascript">
45 // Create a lat/lon object
46 var myPoint = new YGeoPoint('glen burnie md 21060');               
47 // Create a map object
48 var map = new YMap(document.getElementById('mapContainer'));     
49 // Display the map centered on a latitude and longitude
50 map.drawZoomAndCenter('glen burnie md 21060', 1);

51 // Add map type control
52 map.addTypeControl();

53 // Set map type to either of: YAHOO_MAP_SAT YAHOO_MAP_HYB YAHOO_MAP_REG
54 map.setMapType(YAHOO_MAP_SAT);

55 //Get valid map types, returns array [YAHOO_MAP_REG, YAHOO_MAP_SAT, YAHOO_MAP_HYB]
56 var myMapTypes = map.getMapTypes();

57 </script>

58  </head>
59  <body onload="load()" onunload="GUnload()">
60    <div id="map" style="width: 500px; height: 300px"></div>
61  </body>
62 </html>
63 </p>
Link to comment
https://forums.phpfreaks.com/topic/31697-help-with-simple-php-form-data/
Share on other sites

Whenever you post code to this form, please surround the code with the [nobbc][code][/code][/nobbc] tags. Using these tags makes the code much easier to read.

It looks like you're assuming that [url=http://www.php.net/register_globals]register_globals[/url] is enabled. Do not assume this. Also, you are using the obsolete arrays "HTTP_*_VARS" use the new superglobal arrays instead ($_POST, $_GET, $_SERVER, etc.).

In your form, remove the "enctype='multipart/form-data' " clause, since you are not passing any files.

Finally, lines 46 - 50 should look something like:
[code]
var myPoint = new YGeoPoint('<?php echo $city . ' ' . $state . ' ' . $zip; ?>');               
// Create a map object
var map = new YMap(document.getElementById('mapContainer'));     
// Display the map centered on a latitude and longitude
map.drawZoomAndCenter('<?php echo $city . ' ' . $state . ' ' . $zip; ?>', 1);
[/code]

Ken
First let me apologise for not posting correctly. My first visit here, duely noted though.

Secondly, thank you for the proper syntax.  Of all things I tried, echoing the code with php tags was the one thing i though for sure wouldnt work so I didnt even try it.  Guess I was wrong again.

Thanks alot.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.