Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is pretty complicated to answer without going into great detail about the mechanics. Here are hopefully at least some pointers to get you started.</p> <p>First of all, in order to manipulate what is displayed on the page after it's loaded, you're going to have to use Javascript. I would suggest using a library such as <a href="http://jquery.com/" rel="nofollow">jQuery</a> to make things easier on yourself. Here's how I would go about doing it:</p> <p>Give all of your choice-specific form fields/table rows/whatever a class, such as form_websites for the fields that should be displayed when Websites is selected. All of these classes should be defined in a css file with the display: none property so that they are hidden by default.</p> <p>Using jQuery, <a href="http://api.jquery.com/change/" rel="nofollow">add a change handler</a> to your select box in your form to <a href="http://api.jquery.com/css/" rel="nofollow">change the display value</a> to normal. In your script, you'll also need to keep track of which option was selected before so that you can change its display value to hidden. With jQuery, you can actually get as fancy as you want, with animating the fields "opening" and "closing" as needed, you might also want to check out things like jQueryUI's <a href="http://jqueryui.com/demos/accordion/" rel="nofollow">accordion widget</a> and/or <a href="http://jqueryui.com/demos/hide/" rel="nofollow">hide effect</a> and <a href="http://jqueryui.com/demos/show/" rel="nofollow">show effect</a>.</p> <p>When your form is submitted, in your php code, you need to do any reasonable escaping and/or checking to make sure that you don't have malicious code embedded in the data that the user submits. For example, if a field is supposed to be a phone number, use something like a check against <a href="http://php.net/manual/en/function.preg-match.php" rel="nofollow"><code>preg_match("/^\[\\d\\s+\\-\\(\\)\]{1,20}$/",$_POST\["phone_number"\])</code></a> to make sure the user submitted a legal value. If they didn't, ignore or show the user an error page as needed. Just remember: It is <strong>MUCH</strong> easier and safer to check a value against a positive assertion (that is, "It should fit this pattern") than against a negative assertion (that is, "It shouldn't have these characters in it"). If you find yourself testing for injected HTML tags, javascript code, etc., then you're probably doing it wrong, but you might have to resort to it for free-form text fields.</p> <p>In short, like I said, what you're asking to do is actually moderately complicated. Web sites with that degree of interaction aren't easy to write, but hey, that's why web designers make the big bucks. ;)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload