How to create a form |
[eluser]ealonw[/eluser]
Hello all! Im an admin, Linux geek turned coder.. I took to PHP because I work with Mysql on Linux all the time. What Im trying to do is create a simple form in codeigniter that includes: couple input boxes checkboxes and radio button. Can someone give me a good guide on how thats done. I want to write the results to a file and echo a message after the form is complete. I can do this with just PHP scripting but not the codeigniter way. Can anyone help me along. This would be my first time coding using CI and Im really interested in learning. Functions: 1. Fill out the form 2. Write the results to text file 3. Echo message after form complete Attached is the HTML form in TEXT version
[eluser]Pascal Kriete[/eluser]
I don't see an attached file. I highly suggest you watch the video tutorials to get a real feeling of how CI works. That said, most programs use a database instead of a file, but we'll make do. If you don't understand something make sure to check the User Guide first. You'll be in there a lot, so might as well get some practice using it. As always, absolutely untested. Let me know if you have trouble. 1. Make a new file in the Controllers folder and call it test.php. Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 2. Now we need views. Create a file called testform.php in your views folder: Code: <html> 3. And another view called feedback.php : Code: <html> 4. In your config/config.php file change the base_path variable to fit your setup. Now point your browser at: /cidirectory/index.php/test Here's some references to help you understand what I did: Controllers Views Url Helper File Helper For more advanced forms you will also want to take a look at: Validation I know it seems like a lot at first, but just watch those tutorials, play around a bit and you'll be up and running in no time. Remember the forum search and userguide - you'll usually find something. Welcome to CodeIgniter.
[eluser]ealonw[/eluser]
Hmmm that works! Good test! But it wont append to the file using if ( ! write_file('/var/www/html/write/savefile.php', $name, FILE_APPEND)
[eluser]Pascal Kriete[/eluser]
That's because that parameter doesn't exist (form helper). I believe you're used to the file_put_contents function. That's cool, you can use any php function. In this case though, if you want to remain php4 compatible you should load the compat helper first. Code: // PHP 4 support for portability
[eluser]ealonw[/eluser]
Nvermind! I used this instead.. if (file_put_contents('/var/www/html/write/savefile.php', $name."\n\r", FILE_APPEND))
|
Welcome Guest, Not a member yet? Register Sign In |