View Full Version : Form Processor
qwerty
11-04-2005, 20:07/08:07PM
Does anyone know of a free php form processing script that would allow me to set some fields as required, can both send to an email address and populate a flat file (something I could export to Excel) AND is easy to set up?
WebSavvy
12-04-2005, 12:02/12:02PM
No, but I could write one for you (no charge) and it'd take me all of about 20 minutes to do.
I don't use or know anything about Excel, but I can write a php form processor that sends to email and inserts into an MySQL table.
Then from PhpMyAdmin (inside CPanel) you'd just click the export to Excel button on the table.
Would this suit your needs? If so, let me know. I wouldn't be able to get to it until Thursday though.
qwerty
12-04-2005, 12:03/12:03PM
Thanks, but I got one. Everything seems to be working fine now, and I can do without the flat file business. I'm getting emails and that's the most important part.
WebSavvy
12-04-2005, 12:08/12:08PM
OK, good. :)
loki
12-04-2005, 12:15/12:15PM
you can try the attached, rename it to whatever.php
it works nicely for me except on one server, where the txt seems to get corrupted now and again. i've asked for help in several places but the suggestions tend to assume i know something about php, which i don't.
in this case you need to create a subdirectoy htdocs/dan , put a blank app.txt file into it, and give it 777 permsissions.
send to email addresses have failed in the past when they were not from the website's own domain, so it's safer to avoid sending the emails to other domain's addresses.
and it won't work until you've created the redirect page, in this case thanks.html
in general it's solid.
i would like to have the option of 'required fields' and i did ask for help in the 'professional help' not long back but so far noone is interested.
loki
12-04-2005, 12:16/12:16PM
here it is:
WebSavvy
12-04-2005, 12:22/12:22PM
Sorry loki, I must have missed the thread where you asked this. I've been working pretty much round the clock for the better part of a week now.
Anyway, it's very simple to do this:
Let's say you have a field called email that you want to have as a required field.
This is what you do:
<?php
if($email == ""){
echo "You must supply an email address!";
}
?>
The double equal sign == passes the variable through to vaildate it that it must not be empty "" and then echoes the statement you put in the echo field.
Give it a try, and let me know how it goes. If you need any more help with it, just ask in this thread or PM me. OK?
HTH.
loki
12-04-2005, 12:51/12:51PM
that works... but it also gives an ugly message:
You must supply an email address!
Warning: Cannot modify header information - headers already sent by (output started at /home/euroteso/public_html/dan_app2.php:12) in /home/euroteso/public_html/dan_app2.php on line 58
i added in after line 8 this code: if($email == ""){
echo "You must supply an email address!";
}
can i set this so that you don't see the message after the "
You must supply an email address!"
WebSavvy
12-04-2005, 12:56/12:56PM
When the form submits from point A to point B -> that code goes into point B.
In point A it IS empty until either filled or not filled by the user.
Only upon reaching point B does the script even know this.
If you still can't get it to work, I'll download your script from this thread, and add this in for you, myself.
What fields do you want as "required" so I'll know.
BTW ... as stated previously, I can't get to it until about Thursday, though.
loki
12-04-2005, 12:57/12:57PM
deb,
i've just seen that it sends the form contents, even with the empty fields.
i imagine i've added it to the wrong spot, can that be fixed too?
tia
loki
12-04-2005, 13:00/01:00PM
just seen your response deb.
i use this script for lots of forms but if you could show me how to make (say) email and name required fields then i'm sure i could tap dance from there.
:)
WebSavvy
12-04-2005, 13:00/01:00PM
Yep, that can all be fixed really easy. Just leave it go, and around Thursday I'll fix it for you, and then attach the file in this thread for you.
PHP is super easy for me, whereas SEO is something I just don't 'get'. :)
WebSavvy
12-04-2005, 13:03/01:03PM
OK, I'll write a generic form for you, that contains the fields:
email, name, date
I'll make email and name required
date can be left empty
This will give you an idea of how the required and non-required fields would appear together in the form.
(again ... not til Thursday ;))
loki
12-04-2005, 13:14/01:14PM
you're my favourite coder!
ArmenT
12-04-2005, 23:29/11:29PM
loki, your error was because of this:
if($email == ""){
echo "You must supply an email address!";
exit();
}
Without the exit(), it'll continue on and attempt to redirect. Problem is that with the exit(), it will print the message and not take you back to your form.
The sample code below makes name and email required and takes you back to the form, if you didn't enter them. It also retains the values of the already entered fields.
<?
$errstr = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
$email = $_POST["email"];
$date = $_POST["date"];
// Check the values here
if ($name == "")
$errstr .= "Please enter a name.<br>";
if ($email == "")
$errstr .= "Please enter an email.<br>";
if ($errstr == "") {
// No errors here. Do whatever needs to be done here
print "Ta da! You entered $name $email $date";
exit();
}
}
?>
<html>
<head><title>Sample Post Form</title></head>
<body>
<h3>Enter your data here</h3>
<? if ($errstr != "") { ?>
<font color="red"><?=$errstr?></font>
<? } ?>
<form method="POST" action="<?=$PHP_SELF?>">
<!-- Make your page look good here -->
Name: <input name="name" value="<?=$name?>" /><br/>
Email: <input name="email" value="<?=$email?>" /><br/>
Date: <input name="date" value="<?=$date?>" /><br/>
<input type="submit" value="Go for it!" />
</form>
</body>
</html>
Obviously, it could be improved to check if the email is valid and all, but that's another 5 minutes of work maximum.
WebSavvy
13-04-2005, 00:04/12:04AM
Hey Armen, thanks for that. Yep, I missed the exit(); ... happens when you code when you're tired.
:)
Connie
13-04-2005, 00:50/12:50AM
Sorry for the "Pun", 2 heads are always better than one. (Most of the time)
loki
14-04-2005, 08:09/08:09AM
FYI i haven't forgotten this. i'm changing server for the domain i'm chiefly keen on applying this script to so i'll wait until we're resolved to the new one, hopefully on monday, before i try to set this up.
qwerty, (i love typing that !)
my apologies if i've hijacked your thread somewhat; is this what you were after?
qwerty
14-04-2005, 08:34/08:34AM
It's not my thread; I just started it. By the time Deb replied to my first post I'd already found what I needed, so you folks go ahead :)
loki
03-06-2005, 11:45/11:45AM
6 weeks to get back to this, that's a record for me!
ok, i've got it working for arment's code
if($email == ""){
echo "You must supply an email address!";
exit();
}{
but not for his 2nd piece of code with multiple required fields. i think one will do for now so i'll leave it at that.
there is one further item. the form currently call strip_tags and stripslashes, but frm time to time the txt gets corrupted and cannot be added into MSAccess correctly.
i've been told that characters to watch out for would be comma, tab and newline.
how do i add them to this? $_POST[$field] = trim(strip_tags(stripslashes($data)));
TIA
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.