PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ageorghiou
Forum Newbie
Posts: 12 Joined: Fri Oct 28, 2005 6:25 am
Post
by ageorghiou » Fri Oct 28, 2005 6:35 am
I've just written a small php page that receives post data from a form and should save all of the forms to a comma delimited text file. When I test it through Internet Explorer and Safari, the data comes through fine but when using Firefox all I get is commas. Has anyone else had any problem like this before?
The php for receiving the POST data is as follows:
Code: Select all
<?php
$todayis = date("l, F j, Y, g:i a") ;
$visitor = $_POST["visitor"];
$sex = $_POST["sex"];
$age = $_POST["age"];
$visitormail = $_POST["visitormail"];
$visitorjob = $_POST["visitorjob"];
$visitornumber = $_POST["visitornumber"];
$region = $_POST["region"];
$habits = $_POST["habits"];
$you = $_POST["you"];
$joinup = $_POST["join"];
$list = $_POST["list"];
$help = $_POST["help"];
$receive = $_POST["receive"];
$notes = $_POST["notes"];
if (file_exists("joindata.txt")) {
$out = fopen("joindata.txt", "a");
if (!$out) {
print("Could not open file");
exit;
}
}
else {
print("file does not exist");
exit;
}
if(flock($out, LOCK_EX)) {
fwrite($out,"\"$todayis,$visitor,$sex,$age,$visitormail,$visitorjob,$visitornumber,$region,$habits,$you,$joinup,$list,$help,$receive,\"$notes\" \n");
flock($out,LOCK_UN);
}
fclose($out);
?>
Thanks
Andreas
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Oct 28, 2005 6:36 am
it'd help to see your html...
ageorghiou
Forum Newbie
Posts: 12 Joined: Fri Oct 28, 2005 6:25 am
Post
by ageorghiou » Fri Oct 28, 2005 6:52 am
feyd | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Form HTML document:Code: Select all
<HTML>
<HEAD>
<TITLE></TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="text/general.css" type="text/css">
<script src="text/navcode.js"></script>
<script type="text/JavaScript">
<!--
//Need valid email address and name.......
function validateForm(formName) {
var errors='';
frm=document.getElementById(formName);
if(frm.elements[3].value=='') {
errors+='- you must provide your name.\n';
}
if(frm.elements[6].value != '') {
if(frm.elements[6].value.indexOf('@') < 1) {
errors+= '- you must provide a valid email address.\n';
}
}
else if(frm.elements[6].value == '') {
errors+= '- you must provide a valid email address.\n';
}
if (errors) alert('The following error(s) occurred:\n'+errors);
document.returnValue = (errors == '');
}
//-->
</script>
</HEAD>
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<!-- ImageReady Slices (new website slices2.ai) -->
<TABLE WIDTH=461 BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD ROWSPAN=3 ALIGN=left VALIGN=top><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" height="535" width="155">
<param name="movie" value="images/navigation.swf">
<param name="quality" value="best">
<param name="play" value="true">
<embed height="535" pluginspage="http://www.macromedia.com/go/getflashplayer" src="images/navigation.swf" type="application/x-shockwave-flash" width="155" quality="best" play="true">
</object></TD>
<TD COLSPAN=4 valign="top"><IMG SRC="images/head_image.jpg" WIDTH=600 HEIGHT=84 ALT="" align="top"></TD>
</TR>
<tr height="23">
<td colspan="4" height="23"></td>
</tr>
<TR>
<TD COLSPAN=4 ALIGN=left VALIGN=top><IMG SRC="images/nav_6b2.gif" WIDTH=599 HEIGHT=37 ALT="">
<table width="529" border="0" cellspacing="0" cellpadding="0" height="358">
<tr height="5">
<td class="body_black_11" width="7" rowspan="2" height="358"><IMG SRC="images/index_09.gif" WIDTH=7 HEIGHT=225 ALT=""></td>
<td class="body_black_11" width="179" height="5"></td>
<td class="body_black_11" width="11" height="5"></td>
<td class="body_black_11" width="387" height="5"></td>
</tr>
<tr height="353">
<td class="body_black_14" width="179" height="353" valign="top"><br>
<br>
<IMG SRC="images/index_09.gif" WIDTH=180 HEIGHT=2 ALT=""></td>
<td class="body_black_11" width="11" height="353" valign="top"></td>
<td class="body_black_11" width="387" height="353" valign="top"><form id="joinForm" action="joinform.php" method=POST>
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>
<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
Name: <br />
<input type="text" name="visitor" size="35" />
*<br />
<br />
Sex:<br />
<select name="sex" size="1">
<option value=" Female ">Female</option>
<option value=" Male ">Male</option>
</select>
<br />
Age:<br />
<select name="age" size="1">
<option value=" 18-39 ">18-39</option>
<option value=" 40+ ">40+</option>
</select>
<br />
<br />
Email address:<br />
<input type="text" name="visitormail" size="35" />
* <br />
Occupation:<br />
<input type="text" name="visitorjob" size="35" />
<br />
Telephone Number:<br />
<input type="text" name="visitornumber" size="35" />
<br />
<br />
Region:<br />
<select name="region" size="1">
<option value=" Scotland ">Scotland</option>
<option value=" North West England ">North West England</option>
<option value=" London ">London</option>
</select>
<br />
<br />
Voting Habits:<br />
<select name="habits" size="1">
<option value=" a ">a</option>
<option value=" b ">b</option>
<option value=" c ">c</option>
<option value=" d ">d</option>
<option value=" e ">e</option>
</select>
<br />
<br />
You are:<br />
<select name="you" size="1">
<option value=" a ">a</option>
<option value=" b ">b</option>
<option value=" c ">c</option>
<option value=" d ">d</option>
</select>
<br />
<br />
Would you like join the Party?<br />
No
<input type="radio" name="join" value="no" />
Yes
<input type="radio" name="join" value="yes" checked="checked" />
<br />
<br />
Would you like us to add your name to the list of supporters?<br />
No
<input type="radio" name="list" value="no" />
Yes
<input type="radio" name="list" value="yes" checked="checked" />
<br />
<br />
Would you like to help us with a regional visit?<br />
No
<input type="radio" name="help" value="no" />
Yes
<input type="radio" name="help" value="yes" checked="checked" />
<br />
<br />
Would you like to receive e-mail up dates?<br />
No
<input type="radio" name="receive" value="no" />
Yes
<input type="radio" name="receive" value="yes" checked="checked" />
<br />
<br />
Message or comment: (100 word limit)<br />
<textarea name="notes" rows="4" cols="40"></textarea>
<br />
<input type="submit" onClick="validateForm('joinForm');return document.returnValue" value="Submit"/>
<br />
<br />
* indicates required field<br />
<br />
<br />
<br />
</form></td>
</tr>
</table></TD>
</TR>
<TR>
<TD COLSPAN=5 ALIGN=left VALIGN=top><IMG SRC="images/index_13.gif" WIDTH=754 HEIGHT=32 ALT=""></TD>
</TR>
</TABLE>
<!-- End ImageReady Slices -->
</BODY>
</HTML>
joinform.php:
Code: Select all
<HTML>
<HEAD>
<TITLE></TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="text/general.css" type="text/css">
<script src="text/navcode.js"></script>
</HEAD>
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<!-- ImageReady Slices (new website slices2.ai) -->
<TABLE WIDTH=461 BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD ROWSPAN=3 ALIGN=left VALIGN=top><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" height="535" width="155">
<param name="movie" value="images/navigation.swf">
<param name="quality" value="best">
<param name="play" value="true">
<embed height="535" pluginspage="http://www.macromedia.com/go/getflashplayer" src="images/navigation.swf" type="application/x-shockwave-flash" width="155" quality="best" play="true">
</object></TD>
<TD COLSPAN=4 valign="top"><IMG SRC="images/head_image.jpg" WIDTH=600 HEIGHT=84 ALT="" align="top"></TD>
</TR>
<tr height="23">
<td colspan="4" height="23"></td>
</tr>
<TR>
<TD COLSPAN=4 ALIGN=left VALIGN=top><IMG SRC="images/nav_6b2.gif" WIDTH=599 HEIGHT=37 ALT="">
<table width="484" border="0" cellspacing="0" cellpadding="0" height="358">
<tr height="5">
<td class="body_black_11" width="7" rowspan="2" height="358"><IMG SRC="images/index_09.gif" WIDTH=7 HEIGHT=225 ALT=""></td>
<td class="body_black_11" width="368" height="5"></td>
<td class="body_black_11" width="109" height="5"></td>
</tr>
<tr height="353">
<td class="body_black_11" width="368" height="353" valign="top"><p><IMG SRC="images/index_09.gif" WIDTH=180 HEIGHT=2 ALT=""></p>
<div align="left">
<?php
$todayis = date("l, F j, Y, g:i a") ;
$visitor = $_POST["visitor"];
$sex = $_POST["sex"];
$age = $_POST["age"];
$visitormail = $_POST["visitormail"];
$visitorjob = $_POST["visitorjob"];
$visitornumber = $_POST["visitornumber"];
$region = $_POST["region"];
$habits = $_POST["habits"];
$you = $_POST["you"];
$joinup = $_POST["join"];
$list = $_POST["list"];
$help = $_POST["help"];
$receive = $_POST["receive"];
$notes = $_POST["notes"];
if (file_exists("joindata.txt")) {
$out = fopen("joindata.txt", "a");
if (!$out) {
print("Could not open file");
exit;
}
}
else {
print("file does not exist");
exit;
}
if(flock($out, LOCK_EX)) {
fwrite($out,"\"$todayis,$visitor,$sex,$age,$visitormail,$visitorjob,$visitornumber,$region,$habits,$you,$joinup,$list,$help,$receive,\"$notes\" \n");
flock($out,LOCK_UN);
}
fclose($out);
?>
</div></td>
<td class="body_black_11" width="109" height="353" valign="top"></td>
</tr>
</table></TD>
</TR>
<TR>
<TD COLSPAN=5 ALIGN=left VALIGN=top><IMG SRC="images/index_13.gif" WIDTH=754 HEIGHT=32 ALT=""></TD>
</TR>
</TABLE>
<!-- End ImageReady Slices -->
</BODY>
</HTML>
Wasn't sure how to nest the php color coding within the code stuff...
feyd | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Oct 28, 2005 7:11 am
I'm not seeing anything that jumps out as not working for Firefox but working for IE...
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Fri Oct 28, 2005 7:22 am
Got a link to it? Are you hitting enter or clicking the submit button?
ageorghiou
Forum Newbie
Posts: 12 Joined: Fri Oct 28, 2005 6:25 am
Post
by ageorghiou » Fri Oct 28, 2005 7:28 am
It's not up at the moment so no link to it. I can't imagine why it shouldn't work in Firefox either because I though php was server side so shouldn't really concern itself with the browser. I was clicking on submit rather than pushing enter... I should probably do something about my onClick if the enter key won't trigger that.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Fri Oct 28, 2005 7:32 am
I missed the onclick
Check your JS console for errors...
The proper way to validate a form is to use "onsubmit" in the <form> tag.
Code: Select all
function validate()
{
if (/* some condition */) return true;
else return false;
}
//Start HTML
<form onsubmit="return validate();">
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Fri Oct 28, 2005 7:33 am
is there any error reported in Javascript Console
ageorghiou
Forum Newbie
Posts: 12 Joined: Fri Oct 28, 2005 6:25 am
Post
by ageorghiou » Fri Oct 28, 2005 7:36 am
onSubmit. i like it. Thanks for that.
No errors on my javascript console.