PDA

View Full Version : Dynamic Includes


Crowds
05-21-2006, 02:20 PM
In a simple Spry based image gallery I have created a comment script. But I dont want the add comment form to be visible until you press an 'Add Comment' button.
I have done something similar before with a jump menu that worked just fine using the below code


<form name="form1" id="form1">
<select name="artists" onchange="MM_jumpMenu('parent',this,0)">
<option value="index.php?inc=1" selected="selected">Select Artist</option>
<option value="index.php?inc=2">op1</option>
<option value="index.php?inc=3">op2</option>
</select>
</form>
<?

parse_str($_SERVER['QUERY_STRING']);

if (empty($inc)) {

include 'def.php';

} else {

switch($inc) {

case '1':
include_once('def.php');
break;

case '2':
include_once('op1.php');
break;

case '3':
include_once('op2.php');
break;

}

}
?>


I am now trying to adjust this to work on a submit button and I have


<form name="comment" id="comment" action="index.php?inc=1">

<input name="submit" type="submit" value="Add Comment" />

</form>
<?

parse_str($_SERVER['QUERY_STRING']);

if (empty($inc)) {

include 'commentlog.php';

} else {

switch($inc) {

case '1':
include_once('comment.php');
break;

}

}
?>


But it is not working.
Where am I going wrong? or would there be a more simple way of doing this ?

crowds

goughy000
05-21-2006, 02:43 PM
you could use that cool javascript thing. where you can show and hide stuff in a <div> tag.

http://www.netlobo.com/div_hiding.html

anarchy3200
05-21-2006, 03:01 PM
If you did want to stick with your method try printing you $inc value and see if is being set properly, if not try using $_GET['inc'] rather than relying on the parse_str() function or just add $inc = $_GET['inc']; There is nothing there obviously wrong but sometimes things can play up depending on all your PHP settings etc so can need checking.

Crowds
05-21-2006, 04:42 PM
Thanks for the replies. The javascript and css trick (never knew about that one)
works just fine ! so cheers for that goughy000.
Being able to do this via PHP would be handy for future use so i will stick to the js for this project and look into what you have said anarchy3200 for future reference.
Cheers
crowds