Jump to content

Switch Parts of Stylesheet on Reload


himynameismark

Recommended Posts

I am writing a script to register users for a client's website. I have almost all of the validation done using PHP. I will write some Javascript for it too, to check it before the user submits if he or she has Javascript enabled. However, in the case that the user does not have Javascript enabled, I am trying to write a PHP script to reload the form to show errors.In my form, I have a div over each input selection explaining the error, each with it's own specific id. In my validation, I have an error[] array where each part of the array is a form input. For example, error[firstName]. By default, the error divs are hidden. Is there any way I can go into the CSS using PHP and show the error divs based on which input boxes show errors in the validation script when the form reloads?Thanks,Mark

Link to comment
Share on other sites

There is no convenient way to manipulate the styles with PHP. If you still want to use images or divs, you could output the tag for each error with a class/id that CSS can reference.

if (strlen($POST['name']) < 3) {$error_name = '<div id="error_name">Please Enter your Name.</div>';}

And in your form, you could do something like this:

<form action="#" method="POST"><input type="text" name="name" /><?php if (isset($error_name)) echo $error_name;  }?><!--...other fields...--></form>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...