Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old November 15th, 2001, 10:16 AM
mrstang mrstang is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 7 mrstang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question How can I submit info and then forward to another page?

I'm not a complete Newbie, but I am trying to do the following and came to the experts for help.

Our company wants to revise our webpages (boy, they certainly need it -- somebody else did them before I got here). We now want to add a page that includes a form that asks for their name and email address, requiring that they opt-in to our mailing list.

What I have set up is a normal HTML page that includes the forms for Name, Address, and Email Address, etc. Below is the code that I have that works to post the information to my email address here at work, but how can I get it to simulataneously post it to my email address and then forward in the browser to the download page to get our newsletter file?

THANK YOU ahead of time for any help you can give me on this matter. I would like to get this resolved as soon as possible.

Barry


<FORM ACTION="mailtoromotions@thecapitalcorp.com" METHOD="POST" ENCTYPE="text/plain">

<P>Name: <INPUT NAME="name" TYPE="text" VALUE="" SIZE="50" MAXLENGTH="50"></P>

<P>Address: <INPUT NAME="address" TYPE="text" VALUE="" SIZE="50" MAXLENGTH="50"></P>

<P>City: <INPUT NAME="city" TYPE="text" VALUE="" SIZE="50" MAXLENGTH="50"></P>

<P>State: <INPUT NAME="state" TYPE="text" VALUE="" SIZE="50" MAXLENGTH="50"></P>

<P>ZIP Code: <INPUT NAME="zip code" TYPE="text" VALUE="" SIZE="50" MAXLENGTH="50"></P>

<P>Phone Number: <INPUT NAME="phone" TYPE="text" VALUE="" SIZE="50" MAXLENGTH="50"></P>

<P>Email Address: <INPUT NAME="email" TYPE="text" VALUE="" SIZE="50" MAXLENGTH="50"></P>

<p>Please include any message you would like to send to us as well:<BR>
<TEXTAREA NAME="Please Include Any Message:" ROWS="50" COLS="50" WRAP="virtual"></TEXTAREA></P>

<P>
<INPUT TYPE="submit" VALUE="Submit"> <INPUT TYPE="reset" VALUE="Reset form"></P>
</FORM>


Reply With Quote
  #2  
Old November 15th, 2001, 11:25 AM
AlCapone's Avatar
AlCapone AlCapone is offline
Mobbing Gangster
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Sep 2001
Location: "Best City" 2002 and 2003- Melbourne, Australia
Posts: 4,913 AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 36 m 31 sec
Reputation Power: 17
Send a message via ICQ to AlCapone Send a message via AIM to AlCapone Send a message via Yahoo to AlCapone
It would be much easier to do it with any server-side prog language, but you could use js and make it that way so when button is clicked, form is submitted and location changes.
__________________
And you know I mean that.

Reply With Quote
  #3  
Old November 15th, 2001, 11:36 AM
mrstang mrstang is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 7 mrstang User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Do you have an example?

I've tried using some javascript to make it work, but it is not working. Do you have some specific code that I can try to work?

Barry

Reply With Quote
  #4  
Old November 15th, 2001, 10:34 PM
Dr_Jay Dr_Jay is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 1 Dr_Jay User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
If your script is written in PHP, why not just send an http redirect header after the page has been processed? At the end of your code that actually processes the form, add:

header("Location: URL");

Dr_Jay

Reply With Quote
  #5  
Old November 16th, 2001, 06:03 PM
scottiej scottiej is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Posts: 1 scottiej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i need to redirect as well, what if you are checking cases after you submit, and want to redirect if there are no errors

something like:

if (there are no errors)
redirect
else
stay on this page


Thanks in advance

Reply With Quote
  #6  
Old November 16th, 2001, 08:06 PM
Humble Seeker Humble Seeker is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: London
Posts: 69 Humble Seeker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 54 sec
Reputation Power: 7
I think your giving yourself more problems trying to do this with javascript. As Dr_Jay suggested you'r be better of doing this in PHP or some other scripting language. At the moment your approach is internet explorer dependant, netscape 6 dosen't carry the information a cross to the e-mail, at least not on my comp. Also using a server script gives you more control over the who process.

scottiej, try this code checks to make sure that the e-mail is valid, it is it moves to the pages specified in the action part of the form tag. If the e-mail is invalid it goes back to the e-mail input. This validation script is easy to adapt, you only really need checkForm(currForm) with a suitable expression in there.

<html>

<head>
<title>Easy as Pie</title>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
//-- E-mail Validation ---------------------------------------------------------//

function validEmail (email)
{

invalidChars = " /:,;"

if (email == "")
{
return false
}

if (email == "E-mail address")
{
return false
}

for (i=0; i < invalidChars.length; i++)
{
badChar = invalidChars.charAt(i)
if (email.indexOf(badChar, 0) > -1)
{
return false
}
}
atPos = email.indexOf("@", 1)
if (atPos == -1)
{
return false
}

if (email.indexOf("@", atPos + 1) > -1)
{
return false
}
periodPos = email.indexOf (".", atPos)

if (periodPos == -1)
{
return false
}

if (periodPos+3 > email.length)
{
return false
}

return true
}

function checkForm(currForm)
{
if(!validEmail(currForm.email.value))
{
alert("Invalid e-mail address")
currForm.email.focus()
currForm.email.select()
return false
}

return true
}
</SCRIPT>
</head>

<body>
<FORM onSubmit="return checkForm(this) " METHOD=POST ACTION="/Default.asp">
<INPUT TYPE=TEXT NAME="email" VALUE="E-mail address" SIZE=20><BR>
<INPUT TYPE=SUBMIT NAME="newsLetter" VALUE="Submit">
</FORM>
</body>

</html>
__________________
Humble Seeker

The longest journey starts with the smallest step, and knowledge is the longest journey of all.

Reply With Quote
  #7  
Old November 18th, 2001, 12:46 PM
munkfish's Avatar
munkfish munkfish is offline
funky munky
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2001
Location: UK
Posts: 1,446 munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level)munkfish User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 18 h 33 m
Reputation Power: 10
Well, we've got the JavaScript eh? Here's a bit of PHP you could use to take the details a users submits and add them to a file, 'email_list.txt' (in the same directory as the script itself).

I don't know how much you know about PHP, but you could do worse than just placing the script in your webserver's document root (or a subdir of it) and just trying it out

Here's the script - very very simple (apart maybe from the array bit;\) and doesn't do any error checking - I'll leave that for you!

PHP Code:
<?php
// author: <jez han****> ockham_razerAThotmail.com
// 18.11.2001

// mailer.php
// simple mailing script
// get a user's email address from a form, add the email address to a file
// and then redirect the user to our newsletter

// First let's set up some parameters we'll need in the script:

// This variable contains the name of the file we want to save our email address
// submissions to:
$file="email_list.txt";

// location of the newsletter to forward the user to:
// note you need to change this otherwise the script may die!
// use the full URL to the newsletter on the server to be sure
// ie [url]http://mysite.com/news/newsletter.htm[/url]
// (but experiment!)
$newsletter="newsletter.htm";

// Check to see if the form has been submitted:
if($submit=="Submit"){
    
// open the email list file for writing:
    
$fp=fopen($file"a") or die("unable to open file $file for writing");

    
// assign the form items to an array variable:
    
$content=array($name$address$city$state$zip$email);
    
    
// this creates a list like: name||address||city|| etc...
    
$content=join("||"$content);
    
    
// write the info to the file:
    
fputs($fp$content);

    
// close the file:
    
fclose($fp);

    
// redirect the user to your newsletter page:
    
header("Location: newsletter.htm");        
} else {
    
// Form hasn't been submitted yet, display the form:
    // Note we go out of 'PHP mode' to display the HTML here! //
?>
<FORM ACTION="<?php print $PHP_SELF ?>" METHOD="POST"> 
<P>Name: <INPUT NAME="name" TYPE="text" VALUE="" SIZE="50" MAXLENGTH="50"></P> 
<P>Address: <INPUT NAME="address" TYPE="text" VALUE="" SIZE="50" MAXLENGTH="50"></P> 
<P>City: <INPUT NAME="city" TYPE="text" VALUE="" SIZE="50" MAXLENGTH="50"></P> 
<P>State: <INPUT NAME="state" TYPE="text" VALUE="" SIZE="50" MAXLENGTH="50"></P> 
<P>ZIP Code: <INPUT NAME="zip" TYPE="text" VALUE="" SIZE="50" MAXLENGTH="50"></P> 
<P>Phone Number: <INPUT NAME="phone" TYPE="text" VALUE="" SIZE="50" MAXLENGTH="50"></P> 
<P>Email Address: <INPUT NAME="email" TYPE="text" VALUE="" SIZE="50" MAXLENGTH="50"></P> 
<p>Please include any message you would like to send to us as well:<BR> 
<TEXTAREA NAME="Please Include Any Message:" ROWS="50" COLS="50" WRAP="virtual"></TEXTAREA></P> 
<P> 
<INPUT TYPE="submit" NAME="submit" VALUE="Submit"> <INPUT TYPE="reset" VALUE="Reset form"></P> 
</FORM> 
<?php ?>


Heavily commented I'm noticing!!! Can't have too many comments IMO heh
hope that helps/works for you

Reply With Quote
  #8  
Old November 28th, 2001, 03:12 PM
preemi preemi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: Chicago
Posts: 81 preemi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Try using PHP and MySQL

Someone else said use PHP and write it to a file, but it is much smarter to write it to a database. Simply use PHP and MySQL, make sure they are available on the server. When the user hits submit, you want to save all the variables that they enter. In this case, we would want to insert them into your database. At the top of the parsing page (the one you specify in <form action="">) you will have a script to insert the info into the database. Then, you will have plain HTML and embedded PHP to print out the info that they entered. I'm at schol right now, so I doubt my code will be perfect, but e-mail if you have questions.

put the <html> form here and point it to a PHP file.

<?
session_start();

$db_name = "name of your database";
$table_name= "name of your table";
$connection = (login info);
$sql = "INSERT into $db_name (id, fname, lname, email)
VALUES (\"\", \"$fname\", \"$lname\", \"$email\")";
$result = @mysql($connection, $sql);

?>

This will insert the values (shown with the $) that the user entered, into a database. Leave (\"\") for the id, since you will probably want it to be auto-incrementing so if you leave it blank, it will add the next value.

Finally, at the bottom of the same script, you want to add the stuff the user will see.

<html>
<table>
<tr><td>Name:</td><td><? echo "$fname $lname"; ?></td></tr>
<tr><td>Email:</td><td><? echo "$email"; ?></td></tr>
</html>

Thats about it, but like I said, if you have questions, feel free to email me

Reply With Quote
  #9  
Old November 28th, 2001, 03:30 PM
AlCapone's Avatar
AlCapone AlCapone is offline
Mobbing Gangster
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Sep 2001
Location: "Best City" 2002 and 2003- Melbourne, Australia
Posts: 4,913 AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 36 m 31 sec
Reputation Power: 17
Send a message via ICQ to AlCapone Send a message via AIM to AlCapone Send a message via Yahoo to AlCapone
preemi, I have few questions to your example:
1) why do you have session_start and dont use sessions at all
2) you do not connect to mysql
3) why bother escaping " if you can use ' around vars
4) if you dont use returned info from mysql why bother assigning var to it?
5) whats that 'mysql()' thingy? there is no such function.
6) you forgot to close </table>

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > How can I submit info and then forward to another page?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway