CodeIgniter FormValidator Example doesn't work out of the box |
[eluser]futo[/eluser]
Yes, me 2 ![]() I'm two weeks new to CI - but not new to a computer. Normally I'm the guy helping other people. Have tested some code in nginx and now migrated to apache, where I'm starting to implement some forms and there validation. Some form validation code didn't work, and I jumped to the school example from CI to see if that worked: It didn't. I've used two days researching on the en-us part of the internet, and still no solution. form_validation->run() always fails ... Trying the form example from the official CI pages where form_validation->run() always fails. - My base URL in config.php is set with an trailing slash. The code is the same as on the pages of CI: http://ellislab.com/codeigniter/user-gui...ation.html . I've just implemented the first part inclusive 'Setting Validation Rules'. But with no success (I can't reach formsucces.php). I've added this snippet to the code of CI - and it does always return '$_POST is NOT set!'. Code: if(isset($_POST['submit'])){ The code from CI with the above implemented: Code: <?php Any ideas?...
[eluser]CroNiX[/eluser]
This would have to do with your view and we'd need to see how you're constructing your submit button. My guess is you are not naming it "submit". Try doing a dump of the whole $_POST array and see what does come through in POST, instead of just checking to see if "submit" was in POST.
[eluser]CroNiX[/eluser]
Ah, if you copied the code from the guide: Code: <div><input type="submit" value="Submit" /></div> Then your check would be wrong because the submit button does not have a name="submit" attribute. The tutorial should work as posted. It's your extra check for $_POST['submit'] that is extra and causing it to not work. If you name the submit button to "submit" your added check should then work.
[eluser]futo[/eluser]
Thank you very much for your quick response CroNIX! :-D Lovely to hear a helpful voice! :-D [quote author="CroNiX" date="1363976437"]Ah, if you copied the code from the guide: Code: <div><input type="submit" value="Submit" /></div> Then your check would be wrong because the submit button does not have a name="submit" attribute. The tutorial should work as posted. It's your extra check for $_POST['submit'] that is extra and causing it to not work. If you name the submit button to "submit" your added check should then work.[/quote] With the hammer on the nail. Thanks! :-D Now I'm able to see that $POST is set. Wonderful! :-) Now I'm just searching for a hint why I never come to the 'formsuccess.php'?... I have the actual problem that $_POST is empty ... My corrected controller 'form.php': Code: <?php class Form extends CI_Controller { And here is the view 'myform.php' without any changes: Code: <html> <head> <title>My Form</title> </head> <body> I haven't changed anything in 'formsuccess.php' as it doesn't have any influence in the above. Notice the following lines in 'form.php': Code: if(isset($_POST)){ - They return this: Code: $_POST is set! ... even thou I write something in every input field of the form. So, it I'm not surprised that 'form_validation->run()' in the CI-library 'Form_validation.php' returns FALSE. This is meant so by the programmers, as they have these lines in 'Form_validation.php': Code: if (count($_POST) == 0) The questions is why am I getting an empty $_POST ?... I do write something in every input field ... And every input field has a 'form_validation->set_rules' .... and these rules only demands 'required' and nothing more ... I would be delighted for further suggestions :-D ... EDIT-01: Just saw that the topic of $_POST being empty has ruled before: https://www.google.com/search?client=ubu...niter+from+$_POST+empty&ie=utf-8&oe=utf-8 ... I'm investigating this right now ... EDIT-02: As some in other threads suggest it to have with '.htaccess' to do i post this file her: Code: <Files .htaccess> Please share your thoughts to that - and maybe your '.htaccess' ...
[eluser]CroNiX[/eluser]
See if you are receiving ANYTHING via post. I'd do that in index.php at the very top before CI is actually loaded. Then submit your form and see if $_POST is populated. You might try testing some of the various settings for $config['uri_protocol'] in /application/config/config.php Another thing you might try is sticking it in a different method other than 'index' in your formcontroller. And then you'd also need to change your form open tag to point to the new method as it is currently only pointing to the classname (which should call index method), so it'd be form_open('form/your_method'); Are you using an htaccess to remove index.php from the url?
[eluser]CroNiX[/eluser]
Try using only this for your htaccess: Code: RewriteEngine On
[eluser]futo[/eluser]
Started with changing my '.htaccess' to what CroNiX suggested. - No difference. With $config['uri_protocol'] = 'PATH_INFO'; I'm thrown back to '/index.php' when I try to access the controller 'form.php' through 192.168.2.115/form ... the rewrite rules from above acts in this. Setting my '.htaccess' back to what was before. Still nothing useful - just a redirection to the main '/index.php' page in the root (/var/www/index.php - where /var/www/ is the root). Setting my '.htaccess' to what CroNiX suggested again. Changing to $config['uri_protocol'] = 'QUERY_STRING';. Shows no difference to 'PATH_INFO'. Changing to $config['uri_protocol'] = 'ORIG_PATH_INFO';. Shows no difference to 'PATH_INFO'. Changing back to original value: $config['uri_protocol'] = 'REQUEST_URI'; Now the 'form.php' is shown as expected - and not the main '/index.php' - when i write 192.168.2.115/form in the browser. So this definitive rules out $config['uri_protocol'] under the given circumstance. In the beginning af the main '/index.php' file in the root (/var/www/) I set this code: Code: if(isset($_POST)){ This returns the following: Code: index - $_POST is set! Changing the name of the method inside 'form.php' from 'index' to 'yobro' and calling the class and the method in the 'myform.php' with 'form_open('form/yobro')'. The form shows up in the browser as before - and still no values inside $_POST. Also no values inside $_POST by the above code in the main '/index.php'. Yes, I would say that I'm using an htaccess to remove index.php from the url. But looking through my original '.htacces', I'm uncertain now where ...
[eluser]futo[/eluser]
DONE! :-D ... This did it: Code: sudo a2enmod rewrite Source: http://stackoverflow.com/questions/52005...able-empty Quote: All you had to do was enable apache's mod rewrite. Thought this was enabled by standard from Apache ... It wasn't.
[eluser]futo[/eluser]
Thank you very much for standing by and giving advice CroNiX! :-D Have a nice weekend+! :-D |
Welcome Guest, Not a member yet? Register Sign In |