![]() |
Store form data in database and email it to email address x - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Store form data in database and email it to email address x (/showthread.php?tid=27479) Pages:
1
2
|
Store form data in database and email it to email address x - El Forum - 02-12-2010 [eluser]rhand_ci[/eluser] Just started using CI about two weeks ago. Did a few tutorials and am now trying to make my first form that already stores data into a table even though validation is not done yet. What I am wondering about is how I can send this data to an email address and store it into a database at the same time. Here is the controller code I have made so far: Code: <?php And here is the view: Code: <html> Is what I want possible? Any hints how to would be really appreciated! Store form data in database and email it to email address x - El Forum - 02-12-2010 [eluser]Aidy[/eluser] Hey I would take a look at the email class in the user guide.. Store form data in database and email it to email address x - El Forum - 02-12-2010 [eluser]gcc.programmer[/eluser] You can't store the info into the database, and send the email literally at the 'same time', i.e. in parallel, but you certainly can do both. Codeigniter offers an EMAIL CLASS and also a rich set of DATABASE CLASSES that will allow you to do this very thing. Best of all, using codeigniter makes this quite easy, and fun! ;-) Store form data in database and email it to email address x - El Forum - 02-12-2010 [eluser]rhand_ci[/eluser] @ Aidy thanks for the tip... @ gcc.programmer Thanks for the tip + links Will read Email helper again I wil check out and Email library and see if I can combine storing data into a database, which is working and sending it to an email address afterward. Store form data in database and email it to email address x - El Forum - 02-12-2010 [eluser]Neeraj Kumar[/eluser] Following Pseudo Code may help you!! 1. Fetch user data. 2. Process data using form_validation. If valid goto step 3 or goto step 1. 3. Prepare and SQL Query like: 'INSERT INTO table_name VALUES...' 4. Fire Query using $this->db->query(); 5. Then Initialize Email class. 6. Send an Email to the the person 7. Check if email has been successfully sent or not. If successfully sent then exit otherwise goto next step 8. Delete the last entry from the database and throw an error I hope it helps!! Cheers Store form data in database and email it to email address x - El Forum - 02-12-2010 [eluser]rhand_ci[/eluser] @ Codemaster Snake Thanks for this great reply. Here some more questions in response to your post: [quote author="Codemaster Snake" date="1266001306"] 1. Fetch user data. [/quote] I do that using Code: $this->db->insert('rentalform', $_POST); [quote author="Codemaster Snake" date="1266001306"] 2. Process data using form_validation. If valid goto step 3 or goto step 1. [/quote] Validation should not be to hard, but has no priority yet as I try to store data and send it by email first.. [quote author="Codemaster Snake" date="1266001306"] 3. Prepare and SQL Query like: 'INSERT INTO table_name VALUES...' [/quote] Why not just use: Code: $this->db->insert('rentalform', $_POST); [quote author="Codemaster Snake" date="1266001306"] 4. Fire Query using $this->db->query(); [/quote] Query to get the inserted data? How can I query data just sent so I email what was sent and not all table data? [quote author="Codemaster Snake" date="1266001306"] 5. Then Initialize Email class. [/quote] Found this: Code: $this->load->library('email'); [quote author="Codemaster Snake" date="1266001306"] 6. Send an Email to the the person [/quote] using: Code: $this->email->send(); [quote author="Codemaster Snake" date="1266001306"] 7. Check if email has been successfully sent or not. If successfully sent then exit otherwise go to next step [/quote] [quote author="Codemaster Snake" date="1266001306"] 8. Delete the last entry from the database and throw an error [/quote] Why delete the last entry? I would like to store data in database AND email to email address x... Store form data in database and email it to email address x - El Forum - 02-12-2010 [eluser]rhand_ci[/eluser] Just tested sendmail with script I found on CI. I added script to my first controller: Code: <?php And got: Code: Your message has been successfully sent using the following protocol: sendmail So now I just need to read the $_POST array data and add it to the email body. Still working on that... Store form data in database and email it to email address x - El Forum - 02-12-2010 [eluser]jeffpeck[/eluser] You can pick up the post data using $this->input->post('INPUT_NAME') INPUT_NAME is the name of the input from the previous page. So, if you have: <input type="text" name="first_name"/> <input type="text" name="last_name"/> You can get those values on submit through $this->input->post('first_name') and $this->input->post('last_name') Store form data in database and email it to email address x - El Forum - 02-13-2010 [eluser]rhand_ci[/eluser] Thanks a lot Jeffpeck! Going to work on this a bit more this weekend. Will post back as soon as I have some results. Store form data in database and email it to email address x - El Forum - 02-13-2010 [eluser]rhand_ci[/eluser] With the following code data is stored in my table and sent to the designated email address: Code: <?php Just what I needed :-) Now I just need to work on adding more field data to the body in a nice way, validate the form data and improving the controller. |