Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 446
  • Last Modified:

php echo and jquery

Hello Experts,

I have a very small form to email (php script).
The form checks for missing fields such as name and email.

like so

if ($name == "") {
      echo "please fill in your name";
      exit;
      };

Open in new window


I created a div with an absolute position where i would like these messages to appear.
I trying to understand how to integrate jquery to help me show the relevant messages in the absolute positioned div.

can someone show me a quick example please?
0
Refael
Asked:
Refael
1 Solution
 
uzzidesignCommented:
I presume that you want to use jQuery to control the behavior of the message, more than just the position? jQuery in this case would be good to use for hiding the validation messages until they are needed. The best thing to do is to use PHP or jQuery to add or remove classes on the div, and to use those classes as hooks to show/hide and style it with CSS depending on its state. You should do as much as possible with CSS and style on the div itself. You could store different types of messages (e.g., div.error, div.success) in PHP variables and have styles predefined for each class.

One simple method would be to have the div hidden with a display:none until the message appears:
 
if ($('div').is(':empty') {
	$(this).hide();   // toggles display:none
} else {
	$(this).show();   // toggles display:block
}

Open in new window

or a better practice:
if ($('div').is(':empty') {
	$(this).addClass('hidden');	
} else {
	$(this).removeClass('hidden');	
}

Open in new window


But you can get fancier with the jQueryUI library with stuff like dialog popups: http://jqueryui.com/demos/dialog/

Here's an example: http://jsfiddle.net/ChXbr/5/
0
 
RefaelAuthor Commented:
Thank you!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now