 |
|
| Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more. |
|
 |

04-30-2010, 04:22 PM
|
 |
v7n Mentor
Latest Blog: None
|
|
Join Date: 08-08-09
Location: Barbados
Posts: 270
|
|
|
In This Case, What Setting Should I Change In My WAMP Server?
This morning I found a simple but useful PHP form validation script that works as expected when uploaded to my remotely hosted website but doesn’t on my local WAMP server. I’m pretty sure it’s just some setting that needs changing but I don’t know which one.
Anyone got a clue as to what’s happening here? (See attached images - the correct one shows blank fields.)
__________________
If my posts offend thee, I’m just blowing my own horn!
|

04-30-2010, 10:18 PM
|
 |
Super Moderator
|
|
Join Date: 10-29-07
Location: British Columbia, Canada
Posts: 18,049
|
|
|
Hmm, did PHP start?
When you startup Wamp Server there's an icon in the system tray (looks like an odometer). The "needle" moves from left to right as everything starts. When the needle hits the bottom on the right, everything has started.
Did you turn IIS off before you started the Wamp Server? If not, then the Windows server is overriding/conflicting with the Wamp Server.
|

05-01-2010, 07:33 AM
|
 |
v7n Mentor
Latest Blog: None
|
|
Join Date: 08-08-09
Location: Barbados
Posts: 270
|
|
Quote:
Originally Posted by HTMLBasicTutor
Hmm, did PHP start?
When you startup Wamp Server there's an icon in the system tray (looks like an odometer). The "needle" moves from left to right as everything starts. When the needle hits the bottom on the right, everything has started.
Did you turn IIS off before you started the Wamp Server? If not, then the Windows server is overriding/conflicting with the Wamp Server.
|
Well, other PHP scripts run just fine, it's just this one that's throwing up the gibberish. To my knowledge, I don't even have IIS on my computer. (I'm posting this from another computer located miles from mine, so I won't presently be able to confirm that with absolute certainty.)
What else might the problem be?
__________________
If my posts offend thee, I’m just blowing my own horn!
|

05-01-2010, 07:43 AM
|
 |
Super Moderator
|
|
Join Date: 02-10-07
Location: Central Kentucky
Posts: 10,071
|
|
|
If it is a free script tell me where I can get a copy and I will take a look on my localhost here.
Though I must be honest and say that I have encountered a few poorly written ones that would not work on local machine no matter what I did.
EDIT: Duh! I followed the link. Need to go make a drive thru bet on the derby will get back to you.
Last edited by ScriptMan; 05-01-2010 at 07:47 AM.
|

05-01-2010, 10:34 AM
|
 |
Super Moderator
|
|
Join Date: 02-10-07
Location: Central Kentucky
Posts: 10,071
|
|
I unzipped it and it ran fine on my xampp installation which is running php5.
In looking over the script in index.php the only thing I noticed that might be the problem is that the script uses the short tag version which may not be compatible with your WAMP version.
PHP Code:
Name:*<br /><input type="text" name="Name" value="<?=$Name?>" /><br /><br />
The easy thing to try would be to enable short tags on your WAMP. That should be found in your php.ini which is located in your php folder. Use a text editor like notepad or notpad2 to open the file. DO NOT use a word-processor.
Here is a cut from my file. I am including the distribution notes to show you why having this on is not always smart.
PHP Code:
; Allow the <? tag. Otherwise, only <?php and <script> tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable, redistributable code,
; be sure not to use short tags.
short_open_tag = On
To turn it on you may only need to remove the ; from in front of the line or you may need to add the word on or replace off with on. The last line in that cut is the one you need to find and modify.
|

05-01-2010, 02:21 PM
|
 |
v7n Mentor
Latest Blog: None
|
|
Join Date: 08-08-09
Location: Barbados
Posts: 270
|
|
Quote:
Originally Posted by ScriptMan
I unzipped it and it ran fine on my xampp installation which is running php5.
In looking over the script in index.php the only thing I noticed that might be the problem is that the script uses the short tag version which may not be compatible with your WAMP version.
PHP Code:
Name:*<br /><input type="text" name="Name" value="<?=$Name?>" /><br /><br />
The easy thing to try would be to enable short tags on your WAMP. That should be found in your php.ini which is located in your php folder. Use a text editor like notepad or notpad2 to open the file. DO NOT use a word-processor.
Here is a cut from my file. I am including the distribution notes to show you why having this on is not always smart.
PHP Code:
; Allow the <? tag. Otherwise, only <?php and <script> tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable, redistributable code,
; be sure not to use short tags.
short_open_tag = On
To turn it on you may only need to remove the ; from in front of the line or you may need to add the word on or replace off with on. The last line in that cut is the one you need to find and modify.
|
Thanks for your input, ScriptMan but enabling short tags made matters even worse (see attachment). The error notices in the Name, Email, URL and Company fields now state, respectively:
Code:
<br /> <b>Notice</b>: Undefined variable: Name in <b>C:\wamp\www\downloadedFormScripts\form-sample\index.php</b> on line <b>10</b><br />
<br /> <b>Notice</b>: Undefined variable: Email in <b>C:\wamp\www\downloadedFormScripts\form-sample\index.php</b> on line <b>11</b><br />
<br /> <b>Notice</b>: Undefined variable: URL in <b>C:\wamp\www\downloadedFormScripts\form-sample\index.php</b> on line <b>12</b><br />
<br /> <b>Notice</b>: Undefined variable: Company in <b>C:\wamp\www\downloadedFormScripts\form-sample\index.php</b> on line <b>13</b><br />
So that’s not the problem. My hunch is that it has something to do with the eqauls sign (=) immediately following the apparent short open tag in each field. I don’t recall seeing code like that before.
__________________
If my posts offend thee, I’m just blowing my own horn!
|

05-01-2010, 04:11 PM
|
 |
Super Moderator
|
|
Join Date: 02-10-07
Location: Central Kentucky
Posts: 10,071
|
|
What version of php are you running on your WAMP?
If you aren't sure save the following as phpinfo.php as a file on your localhost install and then run it from a browser. It will tell you the entire status.
|

05-01-2010, 06:28 PM
|
 |
v7n Mentor
Latest Blog: None
|
|
Join Date: 08-08-09
Location: Barbados
Posts: 270
|
|
Quote:
Originally Posted by ScriptMan
What version of php are you running on your WAMP?
If you aren't sure save the following as phpinfo.php as a file on your localhost install and then run it from a browser. It will tell you the entire status.
|
PHP Version: 5.3.0
__________________
If my posts offend thee, I’m just blowing my own horn!
|

05-02-2010, 06:24 AM
|
 |
Super Moderator
|
|
Join Date: 02-10-07
Location: Central Kentucky
Posts: 10,071
|
|
|
I really don't know the answer. I do know it is fairly crappy code from a portability point of view.
The shortcut style using the = sign does not work on all servers as you have proven.
Since these script bits don't really do anything except verify the data input, the same thing can be written in a more universal style. Exact what are you trying to do?
|

05-03-2010, 05:17 AM
|
 |
v7n Mentor
Latest Blog: None
|
|
Join Date: 08-08-09
Location: Barbados
Posts: 270
|
|
After lots of effort to improve the script, here's the result. It works like a charm and is XHTML 1.0 compliant as well!
Code:
<?php
$_SESSION['current_url'] = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $_SERVER['QUERY_STRING'];
$url = $_SESSION['current_url'];
if (isset($_POST['submit'])) {
$filename = "../formSubmissions.txt";
$open = fopen($filename, "a");
$DateTime = $_POST['DateTime'];
$url = $_POST['url'];
$name = $_POST['name'];
$email = $_POST['email'];
$comment = stripslashes($_POST['comment']);
$hidden = $_POST['hidden'];
$errorstring = "";
if (!$name)
$errorstring = $errorstring."<li>Name</li>";
if (!$email)
$errorstring = $errorstring."<li>Email</li>";
if (!$comment)
$errorstring = $errorstring."<li>Comment</li>";
if ($errorstring!="") {?>
<form action="" method="post">
<fieldset>
<legend>Comment on this photo</legend>
<p class="warning">Please complete the following field(s):</p>
<ul class="oops"><?php echo $errorstring ?></ul>
<div class="form_row">
<input type="hidden" name="url" value="<?php echo 'Submission via form at ' . $url; ?>" />
<input type="hidden" name="DateTime" value="<?php echo ' on ' . date('l F j, Y \a\t g:i A T'); ?>" /><br />
<label for="name">Name:</label>
<input type="text" id="name" name="name" value="<?php if (isset ($name)) echo $name ?>" />
</div>
<div class="form_row">
<label for="email">Email:</label>
<input type="text" id="email" name="email" value="<?php if (isset ($email)) echo $email ?>" />
</div>
<div class="form_row">
<label for="comment">Comment:</label>
<textarea id="comment" name="comment" rows="" cols=""><?php if (isset ($comment)) echo $comment ?></textarea>
<input type="hidden" name="hidden" value="____________________________________________________________________________________________________________________________________________________________________________" />
</div>
<div class="button">
<button type="submit" name="submit">Submit</button>
</div>
</fieldset>
</form><?php }
else {
fwrite($open, "$url");
fwrite($open, "$DateTime\r\r");
fwrite($open, "Name:\t$name\r");
fwrite($open, "Email:\t$email\r\r");
fwrite($open, "Comment:\r$comment\r\r");
fwrite($open, "$hidden\r\r");
fclose($open);
?>
<form action="" method="post">
<fieldset>
<legend class="thanks">Thank you, <?php echo $name ?>!</legend>
<p>All comments are reviewed before publication.</p>
</fieldset>
</form>
<?php
}
}
if (!(isset($_POST['submit']))) { ?>
<form action="" method="post">
<fieldset>
<legend>Comment on this photo</legend>
<p>All fields are required but your email address will not be shown.</p>
<div class="form_row">
<input type="hidden" name="url" value="<?php echo 'Submission via form at ' . $url; ?>" />
<input type="hidden" name="DateTime" value="<?php echo ' on ' . date('l F j, Y \a\t g:i A T'); ?>" /><br />
<label for="name">Name:</label>
<input type="text" id="name" name="name" value="<?php if (isset ($name)) echo $name ?>" />
</div>
<div class="form_row">
<label for="email">Email:</label>
<input type="text" id="email" name="email" value="<?php if (isset ($email)) echo $email ?>" />
</div>
<div class="form_row">
<label for="comment">Comment:</label>
<textarea id="comment" name="comment" rows="" cols=""><?php if (isset ($comment)) echo $comment ?></textarea>
<input type="hidden" name="hidden" value="____________________________________________________________________________________________________________________________________________________________________________" />
</div>
<div class="button">
<button type="submit" name="submit">Submit</button>
</div>
</fieldset>
</form>
<?php
}
?>
Webmasters whose sites are freely hosted will find this form useful because in many instances, free hosts do not allow forms to email anyone. This form doesn't send email messages. It simply creates a plain text (.txt) file, if such a file does not already exist, and writes the submissions to it.
I'll say more about this form later but gotta run now...
__________________
If my posts offend thee, I’m just blowing my own horn!
|

05-03-2010, 10:30 PM
|
 |
v7n Mentor
Latest Blog: None
|
|
Join Date: 08-08-09
Location: Barbados
Posts: 270
|
|
I should have stated earlier that this form is not meant to be used in standalone mode. It should be embedded into webpages using PHP’s include() function (see attached image: initial_form.png). So when I stated earlier that the form is XHTML 1.0 compliant, I meant that its markup will not screw up previously valid XHTML 1.0 (Strict) pages.
In a nutshell, here are the features of the form: - It’s a single form capable of serving any number of pages
- The “Thank You” message and the form exist on the same page (see attached image: submitted.png)
- Some webhosts hold form submissions in a security queue - sometimes for several hours. There are no such hassles with this form because, as earlier stated, there’s no emailing involved
- When a user forgets to complete a required field, the other fields are not reset on submission. Instead of starting over, the user just needs to fill in the missing field(s) and re-submit the form (see attached image: error_notice.png).
Admittedly, there’s still much that needs to be done to make this form truly “web ready,” if you will. The only validation capability it presently has is to ensure users don’t leave any required fields empty. My intention is to eventually incorporate some sort of CAPTCHA to help stop spambots in their tracks on the one hand, and use more robust validation of genuine entries on the other. Also, the code could have been written more concisely but I’m still learning this stuff!
Besides the link referred to earlier, here are most of the other resources I used to help construct the form:
Here are some tips regarding the form: - If you prefer to first download then read formSubmissions.txt (or whatever you decide to name the file) instead of just reading it online, don’t use Notepad to view it. Instead use something like Notepad++ with word wrap enabled. The formatting will be much better and it will be easier to read.
- The underscores in line 83 of the code serve as a separator between submissions and will need to be changed to suit the width of your window. (I like to use Notepad++ fullscreen on a 16" wide monitor at a resolution of 1440 × 900 pixels.)
- Enable word wrap when viewing submissions containing lengthy textarea entries.
- It has occurred to me that naming the file that submissions will be written to something less obvious than “formSubmissions.txt” might enhance security. Name it something like “Htdi87j0tsVxKld519uzM7.txt” instead!
- Use a service like ChangeDetection to monitor formSubmissions.txt (or whatever you choose to name it). That way, you’ll be notified via email about any new submissions.
BTW, I never knew that is shortcut syntax for However, using the shortened form is not recommended.
Lastly, thanks for your help, HTMLBasicTutor and ScriptMan!
(Originally, the purpose of this thread was just to find a way to change my local server’s settings to successfully use a script. Funny how things get morphed!)
__________________
If my posts offend thee, I’m just blowing my own horn!
|

05-05-2010, 05:37 PM
|
 |
v7n Mentor
Latest Blog: None
|
|
Join Date: 08-08-09
Location: Barbados
Posts: 270
|
|
Quote:
Originally Posted by abajan
...It works like a charm...
|
Except for a flaw I just discovered and fixed: Previously, formSubmissions.txt showed “Submission via form at” for each unsuccessful attempt of a user to submit the form. Despite exhaustive testing, I somehow missed this.
The fix: Go line 27 and change
Code:
<?php echo 'Submission via form at ' . $url; ?>
to
Code:
<?php echo $url; ?>
(Of course, without the fix, you will be able to see how many times users attempt to complete the form, if you find such information useful.)
__________________
If my posts offend thee, I’m just blowing my own horn!
|

05-06-2010, 04:32 AM
|
 |
Super Moderator
|
|
Join Date: 02-10-07
Location: Central Kentucky
Posts: 10,071
|
|
|
What you are doing is the best way to learn PHP. Just be careful about deploying an untested script.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 01:39 PM.
Powered by vBulletin Copyright © 2000-2013 Jelsoft Enterprises Limited.
Copyright © 2003 - 2013 Escalate Media LP
|
|
|