| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: Dec 2005
Posts: 208
![]() | displaying required field errors on the same form using PHP right now i have a form on an html page with form action to the php script page. the php page checks to make sure all the required fields were entered, and if not it will display an error message when the user submits the form. the problem is, that the error message appears on a new page, forcing the user to hit 'back' to go back and fix their mistakes. i am looking for a way to have the errors show up right next to the required fields if left blank when they hit submit. here is a sample of how i have my error checking set up right now: PHP Code: PHP Code: Any help would be great. Thanks.
__________________ + Domains I have for sale here |
| |
| | #2 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,074
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | no the method you have stated there will terminate the script when an error is found. what you need to do is something like the following:- PHP Code: PHP Code: PHP Code:
Last edited by Peter; 11-14-2006 at 12:02 AM.
|
| |
| | THREAD STARTER #3 (permalink) |
| NamePros Regular Join Date: Dec 2005
Posts: 208
![]() | ok thanks alot for your reply. i dont have time to try out what you said right now, but i understand all you wrote and i believe ill get it to work fine. I'll post back later after i fix up my code to let you know if it works for me. Thanks!
__________________ + Domains I have for sale here |
| |
| | THREAD STARTER #4 (permalink) |
| NamePros Regular Join Date: Dec 2005
Posts: 208
![]() | hmm i tried what you said, but i cant get the form to show where it says if(is_array($error)) { OUTPUT FORM HERE } else { NO ERROR EXISTS SO SEND THE EMAIL } How should i get my form to show again? I tried echoing and printing it out, but i get errors when i do that. I am able to have it just print out plain text though. But my form does not work properly. All i am doing to attempt to get the form there, is copy and pasting the form from the html page including with the $city_error code. any ideaS? ok i found a way around this. I copied and pasted my html form into a blank document saved as formsubmit.php and used the following code: PHP Code: Thanks for you help.
__________________ + Domains I have for sale here |
| |
| | #5 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,074
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | using the includes is a perfectly fine way to do it, another way would be within the ifd statement to come out of php output the form then jump back into php. The include yuou have done however will be easier for you to manage. |
| |
| | THREAD STARTER #6 (permalink) |
| NamePros Regular Join Date: Dec 2005
Posts: 208
![]() | it is, thanks for helping with this, i just finished updating my site with all this new functionality - its pretty sweet. yeah i like the includes better, keeps the code shorter and easier to manage like you said.
__________________ + Domains I have for sale here |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |