PDA

View Full Version : Multiple hidden forms, each directing to one or the other



crisp
04-22-2010, 01:35 PM
Hi

I am working to build a multiple hidden forms, with the first as a choice of one set of radio button.

Then i figure i can insert the code <form id="form_start" class="form_start" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> to run a php snippet at the top of the page.

But its the snippet i don't get it. I have worked for days to get this right, but no luck. I've tried different ideas but because i a newbie to php and i haven't had much luck. I've looked all over the web forums for helpful posts too. :)

But its not just one path of hidden forms. There is several forms on the page, but from one visitor to another i want them to show different forms. So in other words each visitor may see one form but someone else may not see that form but see other ones. It just depends on which choice they make with the radio button first up.

Does anyone have code already made for this? Any help at all is greatly appreciated.

Thanks
Steve

bluewalrus
04-22-2010, 09:14 PM
You don't want htmlentities you want to echo just $_SERVER['PHP_SELF']), I think can you post all your code or a link?

crisp
04-23-2010, 01:24 AM
Hi

Thanks for your post.

The code i am working with that i think is a start to what i am trying to achieve is this (above the <head> section):


<?PHP

$o_status = 'unchecked';
$a_status = 'unchecked';

if (isset($_POST['Submit'])) {

$selected_radio = $_POST['form_start'];

if ($selected_radio = = 'o') {
$o_status = 'checked';
}
else if ($selected_radio = = 'a') {
$a_status = 'checked';
}
}

?>

...and this (in the <head> section:


<?PHP
$selected_radio = $_POST['form_start'];
print $selected_radio;
?>

But i think i am a little way off yet.

Thanks in advance.
Steve

traq
04-23-2010, 04:48 AM
I'm not sure I'm clear on what you're actually trying to do.

so, you have two (or more) radio buttons on a page:

( ) radio 1 ( ) radio 2
[ Submit ]

if I select radio 1, I'm shown "content 1", and if I select radio 2, I'm shown "content 2", is that correct?


<?php

if(isset($_POST['Submit'])){

if($_POST['radio'] == 'radio 1'){
echo 'Content 1: You selected button number one!';
}elseif($_POST['radio'] == 'radio 2'){
echo 'Content 2: You selected button number two!';
}else{
echo 'You forgot to select a button.';
showForm();
}

}else{

showForm();

}

function showForm(){

echo '
<form action="'.$_SERVER['PHP_SELF'].'" method="POST">
<input type="radio" name="radio" value="radio 1"> &nbsp;Radio 1 &nbsp;
<input type="radio" name="radio" value="radio 2"> &nbsp;Radio 2<br>
<input type="submit" name="Submit" value="Submit">
</form>';

}

?>

bluewalrus
04-23-2010, 05:01 AM
I think your looking for javascript functionality. Can you post the html form(s) code?

crisp
04-23-2010, 06:51 AM
Hi

Thanks for your posts.

You've caught me a bit on the fly, but iv'e put this together in a hurry as best i could. For example the database php isn't going to function this way. That actually needs to retrieve data from db and then display info in their browser...

I've been playing around with a few ideas and so far i haven't made anything work right.

To try explain again, it goes like this - Yes there is only one radio button, and depending on the selection (after hitting continue) depends on which form is unhidden next. So there could be perhaps 8 different hidden forms on this page but each visitor will see only four or five that are displayed in a sequence after the particular radio button selection another visitor may only see four but what they see will be different forms because the other radio button was selected. Ihope this makes sense.

So i thought something like this with the code...

Full html is here:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<?php

//let's start the session - needs work
session_start();

//now, let's register our session variables
session_register('***');
session_register('*****');

//finally, let's store our posted values in the session variables
$_SESSION['***'] = $_POST['***'];
$_SESSION['*****'] = $_POST['*****'];

?>
<?php

//let's start the session
session_start();

//now, let's register our session variables
session_register('asia');
session_register('middle_east_and_north_africa');
session_register('europe');
session_register('north_america');
session_register('central_america_and_the_caribbean');
session_register('south_america');
session_register('africa');
session_register('australia_and_oceania');

//finally, let's store our posted values in the session variables
$_SESSION['asia'] = $_POST['asia'];
$_SESSION['middle_east_and_north_africa'] = $_POST['middle_east_and_north_africa'];
$_SESSION['europe'] = $_POST['europe'];
$_SESSION['north_america'] = $_POST['north_america'];
$_SESSION['central_america_and_the_caribbean'] = $_POST['central_america_and_the_caribbean'];
$_SESSION['south_america'] = $_POST['south_america'];
$_SESSION['africa'] = $_POST['africa'];
$_SESSION['australia_and_oceania'] = $_POST['australia_and_oceania'];

?>

<?PHP

$o_status = 'unchecked';
$a_status = 'unchecked';

if (isset($_POST['Submit'])) {

$selected_radio = $_POST['form_start'];

if ($selected_radio = = 'o') {
$o_status = 'checked';
}
else if ($selected_radio = = 'a') {
$a_status = 'checked';
}
}

?>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="layout.css" rel="stylesheet" type="text/css" />
<script src="maxheight.js" type="text/javascript"></script>
<?PHP
$selected_radio = $_POST['form_start'];
print $selected_radio;
?>
</head>
<body id="page1" onload="new ElementMaxHeight();">
<div id="main">
<div class="tail-right">
<div class="tail-left">
<!-- header -->
<div id="header">
<div class="row-1">
<div class="fleft"><a href="index.html"><img src="images/logo.gif" alt="" /></a></div>
<div class="fright">
<ul class="list">
<li><a href="#" class="link">Search</a></li>
<li><a href="index-3.html">Add profile</a></li>
<li class="last"><a href="#">Partnership</a></li>
</ul>
</div>
</div>
<div class="row-2">
<div class="form-box">
<div class="inner">
<div class="title"><img src="images/form-box-title.gif" alt="" /></div>
<form id="form_start" class="form_start" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<fieldset>
<legend>What?<br>
(please select):</legend>
<br>
<label><input type="radio" name="form" value="o" > *** ****</label><br>
<label><input type="radio" name="form" value="a" > *************</label><br>
<br>
<br>
<br>
<input type="submit" value="Go To Step 2">
</fieldset>
</form>
<form id="form_1b" method="post" action="form_1c.php">
<div align="center"><br>
<label>Region.</label>
<br>
<input type="checkbox" name="***" value="***" checked>***<br>
<input type="checkbox" name="***" value="***" checked>***<br>
<input type="checkbox" name="***" value="***" checked>***<br>
<input type="checkbox" name="***" value="***" checked>***<br><input type="checkbox" name="***" value="***" checked>***<br>
<input type="checkbox" name="***" value="***" checked>***<input type="checkbox" name="***" value="***" checked>***<br>
<input type="***" name="***" value="hidden">***<br><br>
</div><input type="submit" value="Continue">
</form>
</div>
</div>
</div>
<div class="row-3">
<ul class="site-nav">
<li><a href="index.html"><img src="images/m1-act.gif" alt="" /></a></li>
<li><a href="index-1.html"><img src="images/m2.gif" alt="" /></a></li>
<li><a href="index-2.html"><img src="images/m3.gif" alt="" /></a></li>
<li><a href="index-3.html"><img src="images/m4.gif" alt="" /></a></li>
<li><a href="index-4.html"><img src="images/m5.gif" alt="" /></a></li>
<li><a href="index-5.html"><img src="images/m6.gif" alt="" /></a></li>
</ul>
</div>
</div>
<!-- content -->
<div id="content">
<div class="wrapper">
<div class="col-1 maxheight">
<div class="banner-box">
<div class="inner">
<div class="title"><img src="images/banner-title.gif" alt="" /></div>
<p>Sed ae.</p>
<div class="wrapper"><a href="#" class="link1"><em><b>Click HERE!</b></em></a></div>
</div>
</div>
<div class="box1">
<div class="inner">
<div class="divider">
<div class="wrapper">
<div class="col-1">
<div class="title"><img src="images/1page-title2.gif" alt="" /></div>
<img src="images/1page-img7.jpg" alt="" />
<div class="indent">
<h3><a href="#">Lont.</p>
<div class="wrapper"><a href="#" class="link2">read more</a></div>
</div>
</div>
<div class="col-2">
<div class="line-hor">
<div class="title"><img src="images/1page-title3.gif" alt="" /></div>
<ul class="list2">
<li><a href="#">das</a></li>
<li><a href="#">tase</a></li>
<li><a href="#">maas</a></li>
<li><a href="#">enta</a></li>
</ul>
</div>
<ul class="list2">
<li><a href="#">ss</a></li>
<li><a href="#">yase</a></li>
</ul>
<div class="wrapper"><a href="#" class="link2">and more</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-2 maxheight">
<div class="box maxheight">
<div class="inner">
<div class="title"><img src="images/1page-title1.gif" alt="" /></div>
<ul class="list1 p1">
<li><img src="images/1page-img1.jpg" alt="" /><a href="#" class="link">view details</a></li>
<li><img src="images/1page-img2.jpg" alt="" /><a href="#" class="link">view details</a></li>
<li><img src="images/1page-img3.jpg" alt="" /><a href="#" class="link">view details</a></li>
<li><img src="images/1page-img4.jpg" alt="" /><a href="#" class="link">view details</a></li>
<li><img src="images/1page-img5.jpg" alt="" /><a href="#" class="link">view details</a></li>
<li><img src="images/1page-img6.jpg" alt="" /><a href="#" class="link">view details</a></li>
</ul>
<div class="wrapper"><a href="#" class="link2">more profiles</a></div>
</div>
</div>
</div>
</div>
</div>
<!-- footer -->
<div id="footer">
<div class="inner">
<div class="divider">
<div class="fleft"> &copy; 2010 &nbsp;|&nbsp; <a href="index-6.html">Privacy policy</a></div>
<div class="fright"> <span>E-mail: <a href="#">@ourmail.com</a></span> </div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>


Thanks
Steve

crisp
04-23-2010, 10:15 AM
Hi

Thanks for the code.

See code here:


<?php

if(isset($_POST['Submit'])){

if($_POST['radio'] == 'radio 1'){
echo 'Content 1: You selected button number one!';
}elseif($_POST['radio'] == 'radio 2'){
echo 'Content 2: You selected button number two!';
}else{
echo 'You forgot to select a button.';
showForm();
}

}else{

showForm();

}

function showForm(){

echo '
<form action="'.$_SERVER['PHP_SELF'].'" method="POST">
<input type="radio" name="radio" value="radio 1"> &nbsp;Radio 1 &nbsp;
<input type="radio" name="radio" value="radio 2"> &nbsp;Radio 2<br>
<input type="submit" name="Submit" value="Submit">
</form>';

}

?>

Can i use this to display a hidden form? For examply if i run an 'echo' and it shows a hidden form? Is there code for that?

Thanks
Steve

traq
04-23-2010, 02:28 PM
I think you need javascript. You can use PHP to accomplish what you're doing, but it will be slow, because you're asking the server to re-process the whole page each time. Using javascript, you'd be able to have show/hide functionality on the client side.

BTW, this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<?php

//let's start the session - needs work
session_start();
WON'T WORK. It needs to be like so:

<?php
session_start();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
Nothing can be output before starting your session, or it will throw an error.

crisp
04-24-2010, 02:17 AM
OK. I see. Thanks.
Will look at js.
Steve