PandaFi Posted September 25, 2007 Share Posted September 25, 2007 Hi, I don't know the first thing about coding, and need some help. I need to design a page in php that would be a simple form where the user inputs their email address into a box, with a submit button. After submitting the email address however, I need a few things to happen: 1. Process the form data 2. Validate the E-mail address 3. Check to see if the email address is already been inputted 4. If not then continue 5. I then need to send a code from my "code table" to their email address automatically. This is for an online psychology experiment with two conditions (two sets of codes) and I need to alternate between these conditions when codes are sent out. Can anyone help. I had someone from uni design the rest of the site for me, but now they won't help me do this bit. How would I go about doing this sort of thing? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/70628-complete-noob-needs-help/ Share on other sites More sharing options...
Dragen Posted September 25, 2007 Share Posted September 25, 2007 try looking in the tutorials section on this site. They've got some great tutorials on just about everything to get you started. What you're wanting to do sounds quite simple so look up some php email scripts and come back with what you've got! Then we can help you work on it Also try looking on php.net Quote Link to comment https://forums.phpfreaks.com/topic/70628-complete-noob-needs-help/#findComment-354950 Share on other sites More sharing options...
PandaFi Posted September 25, 2007 Author Share Posted September 25, 2007 Thanks, I'll give it a try :S Quote Link to comment https://forums.phpfreaks.com/topic/70628-complete-noob-needs-help/#findComment-354953 Share on other sites More sharing options...
PandaFi Posted September 25, 2007 Author Share Posted September 25, 2007 I give up!!! I'm rubbish with code...I'll just stick to things I know...and it's not code! Quote Link to comment https://forums.phpfreaks.com/topic/70628-complete-noob-needs-help/#findComment-354987 Share on other sites More sharing options...
Robkid Posted September 25, 2007 Share Posted September 25, 2007 There are many pieces of sample code on doing what you want try googling around a bit Quote Link to comment https://forums.phpfreaks.com/topic/70628-complete-noob-needs-help/#findComment-354990 Share on other sites More sharing options...
PandaFi Posted September 25, 2007 Author Share Posted September 25, 2007 What would I be googling? All i can find is comment forms...which is not what i want. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/70628-complete-noob-needs-help/#findComment-354994 Share on other sites More sharing options...
Dragen Posted September 25, 2007 Share Posted September 25, 2007 a comment form would work in pretty much the same way. All you really need is the script which sends the email. The form is just a simple html form. here's an example form for you: <form action="sendmail.php" method="post"> <input type="text" maxlength="255" name="email" value="" /> <input type="submit" name="submit" value="send" /> </form> If you don't know html I'll quickly explain what that does. <form action="sendmail.php" method="post"> // this tells the server that the next part is a form. The action is generally the page the form is sent to to verify the details, send email etc. the method should usually be left as post. // <input type="text" maxlength="255" name="email" value="" /> // this creates the input field for users to add their email address. the maxlength="255" means that they can only enter up to 255 characters (which I believe is the max for an email address) // <input type="submit" name="submit" value="send" /> // this is the submit button to send the form. the value is the text displayed on the button // then finally: </form> // this tells the server that this is the end of the form // Quote Link to comment https://forums.phpfreaks.com/topic/70628-complete-noob-needs-help/#findComment-355004 Share on other sites More sharing options...
cooldude832 Posted September 25, 2007 Share Posted September 25, 2007 You come here asking for help, but you don't want to put an effort into this, if you can't try we can't help, if you need it that badly pay for it. Quote Link to comment https://forums.phpfreaks.com/topic/70628-complete-noob-needs-help/#findComment-355007 Share on other sites More sharing options...
KevinM1 Posted September 25, 2007 Share Posted September 25, 2007 Hi, I don't know the first thing about coding, and need some help. I need to design a page in php that would be a simple form where the user inputs their email address into a box, with a submit button. After submitting the email address however, I need a few things to happen: 1. Process the form data 2. Validate the E-mail address 3. Check to see if the email address is already been inputted 4. If not then continue 5. I then need to send a code from my "code table" to their email address automatically. This is for an online psychology experiment with two conditions (two sets of codes) and I need to alternate between these conditions when codes are sent out. Can anyone help. I had someone from uni design the rest of the site for me, but now they won't help me do this bit. How would I go about doing this sort of thing? Thanks The best advice I can give you is to try to design the individual steps separately, so you don't lose the forest for the trees, so to speak. 1. Process an e-mail address: You have a form on your site that accepts an e-mail address, correct? If so, then this is basically done for you. 2. Validate the e-mail address: This can be tricky as form validation is typically done through the use of regular expressions, which is a fancy term for creating a pattern and accepting (or denying) inputed data based on that pattern. One pattern I like to use is: <?php function myEscape($string){ return get_magic_quotes_gpc() ? mysql_real_escape_string(stripslashes($string)) : mysql_real_escape_string($string); } if(isset($_POST['email'])){ if(preg_match('/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/i', $_POST['email'])){ $email = myEscape($_POST['email']); } } . . . ?> First, a word of warning: the code snippet above won't work 'out of the box.' So, you can't just copy and paste it into your code and expect results. The important parts of the code snippet are the if-conditionals. The first says "If the email input is set with a value...." The second says "...and if it matches this confusing pattern, then set a local variable named $email with an escaped (i.e. safe for database storage) version of that value." Feel free to use that pattern. 3. Check to see if the e-mail address has already been inputed: This requires accessing a database or file. I'm assuming it's a database, since that's how these things tend to work. I'm also assuming that it's a MySQL database. You could do something like: <?php $query = "SELECT * FROM table_name WHERE email = '$email'"; $result = mysql_query($query); if($result){ //e-mail address is in the database //do something with it } else{ //e-mail is NOT in the database -- insert it $insertQuery = "INSERT INTO table_name (email) VALUES ($email)"; $insertResult = mysql_query($insertQuery); if(mysql_num_rows() == 1){ //success! } else{ //couldn't enter the e-mail address into the database } } ?> Again, this won't work out of the box, but it should get you started. The value for table_name is whatever the name of your particular database table is. The lines beginning with // are where you may need to flesh things out, especially the last two. 4. If not, then continue: This was covered with step 3. 5. I then need to send a code from my "code table" to their email address automatically: Again, this isn't too difficult. The biggest hurdle is probably selecting the right code to send from your code table, assuming they're not all the same. <?php $codeQuery = "SELECT code FROM code_table_name WHERE some_value = '$someValue'"; $codeResult = mysql_query($codeQuery); $row = mysql_fetch_assoc($codeResult); $code = $row['code']; mail($email, 'Subject goes here', $code); //$email is the e-mail address we obtained earlier ?> Again, this is just supposed to give you an idea on how to proceed. Things like $someValue and whatnot are placeholders for values in your actual system. Hope this gives you some idea on how to move forward! Quote Link to comment https://forums.phpfreaks.com/topic/70628-complete-noob-needs-help/#findComment-355022 Share on other sites More sharing options...
PandaFi Posted September 25, 2007 Author Share Posted September 25, 2007 It's not that I don't try...I don't understand very well! But I've got it sorted now. Thanks for your helps though guys. Quote Link to comment https://forums.phpfreaks.com/topic/70628-complete-noob-needs-help/#findComment-355142 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.