PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
This code works find for me in that it validates two fields that if left empty (the Name and Details) it will return an error with the messages displayed. My problem is that if I enter information into say the ‘Details’ field only and leave the ‘Name’ blank the validation runs and a message displays an error beside the relevant field saying 'You must give your name' but at this point it clears both fields which is very annoying especially if someone had gone to the trouble to leave a large text message and forgets to insert their name.
Can anyone help me sort this as I’m very new to PHP and thought that I was getting somewhere with this up to now. I appreciate that I need some sort of variable that will hold the value but I don’t know how to do this.
Many thanks
Brian
Thanks to both of you very much for your help I really appreciate this. As I’m so new to PHP can I ask you to elaborate when you say “you can echo out the posted fields inside the text output”.
Do you mean to use another if and else type statement to hold the values?
Sorry for my ignorance but I’m learning fast.
Brian
Hi,
Thanks for all your help. I have been bashing away for a good few days but I fear that (as a beginner) I’m still struggling and return for help. Basically I have managed to get the following code to work (and hold the values in the fields) but only to a limited extent.
If I leave any of my fields blank I get the correct error telling me to pop in the necessary info. If I put in a name only a funny thing happens in that the name I have popped in turns up in place of the error message “Name Required” instead.
If I go on to enter both fields nothing happens in that the both errors still return.
If you copy and past the code below it will become clear as to my difficulties.
Any help would at this stage be most welcome as I’m just going around in circles albeit it a learning one.
Thanks a ton!
Brian
Thanks for your help.
I’m not fully sure I follow you at this time but why would one work and not the other. For example if the ‘Message’ field is filled in and not the ‘Name’ field it doesn’t print out the message details unlike it would do it this process was reversed.
I thought that I could simply apply the same code to both fields obviously with individual variables i.e. nomessage and nomessage_name.
Sorry for my ignorance here but I’m trying hard to understand all this stuff.
your GuestDetails field is being stored as $message, not $nomessage. Your GuestName field is being stored as $nomessage_name, the same with your error for that field.