Help with Scripts, forms, etc.

Help with Scripts, forms, etc.

Posted by: fatgreta
Posted on: 2005-09-21 15:41:00

Hello.

I'm not sure if this is the forum for this post, but there are no posts in e-commerce so I'll try it here and see what happens. I'm hoping to add a form to my webpage that collects names and email addresses, then directs the person to a download page. I'm pretty sure I can create the necessary form, but I don't know anything about putting it up, or getting it to work as I hope to. If anyone can point me to any good resources where I might learn that stuff, without being too technical, I'd greatly appreciate.

Thanks,

Chris

Re: Help with Scripts, forms, etc.

Posted by: scjessey
Posted on: 2005-09-21 17:10:00

In reply to:

I'm hoping to add a form to my webpage that collects names and email addresses, then directs the person to a download page.


The normal way of doing this would be this:

(a) User fills in form and hits Submit
(b) Form data is collected by a PHP script and sent to a MySQL database file.
(c) Script redirects to download page.

Presumably, the download page will only work if a user has filled in the form, so you could setup MySQL to return a unique ID (following the data insert) that the download page can recognize.

You therefore need a basic understanding of PHP and MySQL to do a thorough job of this.

Alternatively, you can have the script email you the form data. The PHP script that handles the form data must be capable of figuring out whether or not it is okay to redirect to the download page.

Re: Help with Scripts, forms, etc.

Posted by: fatgreta
Posted on: 2005-09-21 17:44:00

Thanks Simon.

I've read what you posted and poked around some more on my Dreamhost control panel. I wonder if you (or anyone else) would mind reading this and telling me if I'm on the right track, recommend avenues for further study, etc.

I see that I can set up a mysql database pretty easily. Once I do that, is it easy to edit? I'll only really be collecting names & email addresses, so it won't be too extensive - can I edit it to compile just two fields worth of data? Once I have a functional database, can I download the information periodically and clear the database to start over? I've found some PHP / My SQL Tutorials on the web which I'll read over the next week or so.

I also know that Dreamhost provides formmail for free, along with detailed instructions. I see a redirect command there, which I assume will direct the visitor to a page I choose. I also see a field called "required" which will allow me to ensure that anyone who doesn't fill in the fields cannot go on to the next page. I don't know, though, if there's a way for me to insure that they give a valid email address. I suppose I could redirect them to an autoresponder and email them a link to the download page? Or maybe I need to know some more coding to make that happen?

Well, as always, thank you for any help.

Chris

Re: Help with Scripts, forms, etc.

Posted by: scjessey
Posted on: 2005-09-21 17:53:00

In reply to:

I see that I can set up a mysql database pretty easily. Once I do that, is it easy to edit?


DreamHost makes phpMyAdmin available to you, which makes it very easy to add, edit, and delete tables, fields, and records. It also allows you to export your data in various different ways.

In reply to:

I also know that Dreamhost provides formmail for free, along with detailed instructions. I see a redirect command there, which I assume will direct the visitor to a page I choose. I also see a field called "required" which will allow me to ensure that anyone who doesn't fill in the fields cannot go on to the next page. I don't know, though, if there's a way for me to insure that they give a valid email address.


I'm afraid I'm not familiar with formmail, since I always write my own things to do this; however, if you have a basic knowledge of PHP, it is actually quite easy to do. Validating email addresses is not a difficult task to do, but it is easy for someone to give you a perfectly valid, but totally bogus address. Emailing them a link to the download page certainly gets around that problem. PHP can easily handle the email aspect as well.

Re: Help with Scripts, forms, etc.

Posted by: fatgreta
Posted on: 2005-09-21 17:58:00

All right, thanks so much. I'll start learning PHP!

Thank you,

Chris

Re: Help with Scripts, forms, etc.

Posted by: scjessey
Posted on: 2005-09-21 18:05:00

In reply to:

All right, thanks so much. I'll start learning PHP!


There is quite a lot of basic information about PHP on the DreamHost Wiki:
http://wiki.dreamhost.com/index.php/PHP

I also created a companion article that demonstrates how to use PHP to connect to and query a MySQL database: http://wiki.dreamhost.com/index.php/MySQL_and_PHP

Re: Help with Scripts, forms, etc.

Posted by: fatgreta
Posted on: 2005-09-21 20:36:00

Whoa!

I set up a database, and that PHP My Admin place is totally confusing - is there a "for beginner's" tutorial anyplace? I've got a database, and I've created two fields, "Name" and "Email" but I don't have a clue where to go from there. What I want to do is figure out how to get the data that people enter into my form into the database, so I can collect the leads for follow up emails. I may be getting in over my head here?

Thanks,

Chris

Re: Help with Scripts, forms, etc.

Posted by: decswxaqz
Posted on: 2005-09-22 02:48:00

I've not actually tried the code below. It's done from experience :P. But it should get you on the right track.
Takes a name and email address. If they are empty or the email is not valid, it won't send an email. Once it's valid, it will send an email to the person with a link to the download page, and it will also send you an email with their details.
You should look at the code in the second file and try to understand what happens.
It's not the best or most robust but it should help you get to understand some PHP. It's always good to know PHP if you are making web sites =). Good luck!

form.html

In reply to:


<form action="form_submit.php" method="post">
Name: <input type="text" name="name" size="30" maxlength="30">
Email: <input type="text" name="email" size="30" maxlength="60">
</form>


form_submit.php

In reply to:


<?php
$sender = "your@email_address.com";
$subject = "Download my files";
$subject2 = "Someone has requested a download";
$message = 'Put your message in here. Put your link in the next sentence. http://www.domain.com/my_download_page.html is where you can download my files.';
$message2 = '$name with email $email from IP $ip has requested a download';

$name = trim($_POST['name']);
$email = trim($_POST['email']);

if(empty($name) || empty($email)){
echo "Some fields were left empty. <a href="form.html">Please go back and try again</a>.";
}
elseif(!preg_match("/^(.+)@[a-zA-Z0-9-]+.[a-zA-Z0-9.-]+$/si", $email)){
echo "This is not a valid email. <a href="form.html">Please go back and try again</a>.";
}
else{
mail($email, $subject, $message, "From: $sender");
$message2 = str_replace('$name', $name, $message2);
$message2 = str_replace('$email', $email, $message2);
$message2 = str_replace('$ip', $_SERVER['REMOTE_ADDR'], $message2);
mail($sender, $subject2, $message2, "From: $sender");
echo "An email has been sent to the address given, please check your email for it";
}
?>


Re: Help with Scripts, forms, etc.

Posted by: bygodaddy
Posted on: 2005-09-22 07:14:00

Chris - another option is to "outsource" this work to an autoresponder service. e.g. aweber.com and there are others.

Just a suggestion if you are spending too much time learning sql , php, etc. for this fairly common task.

Cheers,
Peter


Re: Help with Scripts, forms, etc.

Posted by: artgeek
Posted on: 2005-09-22 09:02:00

In reply to:

I also know that Dreamhost provides formmail for free, along with detailed instructions. I see a redirect command there, which I assume will direct the visitor to a page I choose. I also see a field called "required" which will allow me to ensure that anyone who doesn't fill in the fields cannot go on to the next page. I don't know, though, if there's a way for me to insure that they give a valid email address. I suppose I could redirect them to an autoresponder and email them a link to the download page? Or maybe I need to know some more coding to make that happen?


I think the formmail solution should work too, if soft security is ok.

Tags: email addressesdirectswebpagehopingscriptse commercenameshopestufftechnicaladdhelpappreciate