|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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="mailto romotions@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> ![]() |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
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 |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
||||
|
||||
|
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:
Heavily commented I'm noticing!!! Can't have too many comments IMO heh hope that helps/works for you
__________________
FreeBSD Admin Tips Tricks and Scripts |
|
#8
|
|||
|
|||
|
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 |
|
#9
|
||||
|
||||
|
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> |
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > How can I submit info and then forward to another page? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|