Posted: Fri Nov 26, 2004 6:59 pm
Ok. I give up. It will put out the first page only and when you hit submit, it just falls through the if blocks and reposts the first page.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
<?php
if(isset($_POST['submit3'])){
for($i=0; $i< $_POST['number']; $i++) {
$form_block = '
<fieldset>
<p>Car '.$i.' is
a '.$_POST['name-'.$i].' and has
a '.$_POST['engine-'.$i].' engine
with '.$_POST['doors-'.$i].' doors.</p>
</fieldset>
';
}
}
if(isset($_POST['submit'])) {
$form_block = '
<form method = "post" action = "page3_a.php">
';
$number = $_POST['number'];
for($i = 0; $i < $_POST['number']; $i++) {
$form_block .='
<fieldset>
<p>Name: <input type = "text" name = "name-'.$i.'">
<p>Engine: <input type = "text" name = "engine-'.$i.'">
<p>Number of Doors: <br />
<input type = "radio" name = "doors-'.$i.'" value = "two">Two
<input type = "radio" name = "doors-'.$i.'" value = "three">Three
<input type = "radio" name = "doors-'.$i.'" value = "four">Four
</fieldset>
';
}
$form_block .= '
<input type = "hidden" name = "number" value = "'.$number.'">
<input type = "submit" name = "submit2" value = "Next">
';
}
else {
$form_block = '
<form method = "post" action = "page2_a.php">
<p>How many cars? <input type = "text" name = "number" >
<input type = "submit" name = "submit" value = "Go"><br />
</form>
';
}
?>
<html>
<head></head>
<body>
<?php echo "$form_block";?>
</body>
</html>
?>Code: Select all
<input type = "text" name = "foo" value = "value">
do like this:
<input type="text" name="foo" value="value">Code: Select all
// codeCode: Select all
// more codeCode: Select all
// even moreCode: Select all
Code: Select all
Notice: Undefined variable: form_block in C:\WebDev\Work Directory\Zend\Arrays\single\All_in_One.php on line 36Code: Select all
<?php
if(isset($_POST['submit']) || isset($_POST['submit2'])) {
if(isset($_POST['submit'])) {
$form_block .= '
<!-- <form method = "post" action = "page3_a.php"> --!>
<form method="post" action='.$_SERVER['PHP_SELF'].'>
';
$number = $_POST['number'];
for($i=0; $i < $_POST['number']; $i++) {
$form_block .='
<fieldset>
<p>Name: <input type="text" name="name-'.$i.'">
<p>Engine: <input type="text" name="engine-'.$i.'">
<p>Number of Doors: <br />
<input type="radio" name="doors-'.$i.'" value="two">Two
<input type="radio" name="doors-'.$i.'" value="three">Three
<input type="radio" name="doors-'.$i.'" value="four">Four
</fieldset>
';
}
$form_block .= '
<input type="hidden" name="number" value="'.$number.'">
<input type="submit" name="submit2" value="Next">
';
}
if(isset($_POST['submit2'])){
//var_dump($_POST);
//echo '<pre>';
//print_r($_POST);
for($i=0; $i< $_POST['number']; $i++) {
$form_block .= '
<fieldset>
<p>Car '.$i.' is a '.$_POST['name-'.$i].' and has a '.$_POST['engine-'.$i].' engine with '.$_POST['doors-'.$i].' doors.</p>
</fieldset>
';
}
}
}
else {
$form_block .= '
<!--<form method = "post" action = "page2_a.php">--!>
<form method="post" action='.$_SERVER['PHP_SELF'].'>
<p>How many cars? <input type="text" name="number" >
<input type="submit" name="submit" value="Go"><br />
</form>
';
}
?>
<html>
<head></head>
<body>
<?php echo "$form_block";?>
</body>
</html>
?>Code: Select all
<?php
if(isset($_POST['submit2'])){
//var_dump($_POST);
//echo '<pre>';
//print_r($_POST);
$form_block = '
';
for($i=0; $i< $_POST['number']; $i++) {
echo '
<fieldset>
<p>Car '.$i.' is a '.$_POST['name-'.$i].' and has a '.$_POST['engine-'.$i].' engine with '.$_POST['doors-'.$i].' doors.</p>
</fieldset>
';
}
$form_block .='
';
}
?>wadesmart wrote:Ok. I changed all the input name = value to input name=value.
I dont understand though what you mean about the $form_block.
I thought if you have a single script that you need to break into parts, you sue $form_block = ' at the beginning and then with the parts you use $form_block .= ' . If you use $form_block .= every where you get errors like this one:Code: Select all
Notice: Undefined variable: form_block in C:\WebDev\Work Directory\Zend\Arrays\single\All_in_One.php on line 36
Wade
Code: Select all
$form_block = ''; // define it
if(isset($_POST['submit']) || isset($_POST['submit2'])) {Code: Select all
<?php
if(isset($_POST['accounts'])) {
// set title
$title = "Missing Form Information";
$form_block = '
<h3>Account Information Missing</h3>
<form method="post" action='.$_SERVER['PHP_SELF'].'>
';
var_dump($_POST);
echo '<pre>';
print_r($_POST);
for($j=0; $j < $_POST['accounts']; $j++) {
$form_block .= '
<fieldset>
<p>Account '.$j.'</p>
<ul>
';
if(empty($_POST['name-'.$j])){
$form_block .= '
<li>Account Name: <input type="text" name='.$_POST['name-'.$j].'> </li>
';
}
else {
$form_block .= '
<li>Account Name: '.$_POST['name-'.$j].'</li>
';
}
if(empty($_POST['number-'.$j])){
$form_block .= '
<li>Number: <input type="text" name='.$_POST['number-'.$j].'></li>
';
}
else {
$form_block .= '
<li>Account Number: '.$_POST['number-'.$j].'</li>
';
}
if(empty($_POST['telephone-'.$j])){
$form_block .= '
<li>Telephone: <input type="text" name='.$_POST['telephone-'.$j].'></li>
';
}
else {
$form_block .= '
<li>Account Telephone: '.$_POST['telephone-'.$j].'</li>
';
}
if(empty($_POST['acct_holder-'.$j])){
$form_block .= '
<li>Account Owner: <input type="text" name='.$_POST['acct_holder-'.$j].'></li>
';
}
else {
$form_block .= '
<li>Account Owner: '.$_POST['acct_holder-'.$j].'</li>
';
}
if(empty($_POST['AcctStatus-'.$i])){
$form_block .= '
<p>Account Status: <br >
<input type="radio" value="Open" name='.$_POST['AcctStatus-'.$i].' >Open <br >
<input type="radio" value="Closed" name='.$_POST['AcctStatus-'.$i].' >Closed <br >
<input type="radio" value="Open_Paid_Off" name='.$_POST['AcctStatus-'.$i].' >Open but Paid Off <br >
<input type="radio" value="Closed_Paid_Off" name='.$_POST['AcctStatus-'.$i].' >Closed and Paid Off <br >
<input type="radio" value="Open_Suspended" name='.$_POST['AcctStatus-'.$i].' >Open but Suspended <br >
</p>
<br />
';
}
else {
$form_block .= '
<li>Account Status: '.$_POST['AcctStatus-'.$i].'</li>
';
}
$form_block .='
</ul>
</fieldset>
';
}
$form_block .='
<input type="submit" name="checked" value "Next">
</form>
';
}
//2) Fill in New Account Information
if(isset($_POST['Accts'])) {
// set title
$title = "Add Account Information";
// get number of accounts
$form_block = '
<h3>Add New Account</h3>
<form method="post" action='.$_SERVER['PHP_SELF'].'>
';
// create loop to make form fields
for($i=0; $i<$_POST['num_of_accts']; $i++) {
$form_block .='
<fieldset>
<p>Account Information: '.$i.' <br />
<ul>
<li>Name:<input type="text" name="name-'.$i.'"></li>
<li>Number:<input type="text" name="number-'.$i.'"></li>
<li>Telephone:<input type="text" name="telephone-'.$i.'"></li>
<li>Owner:<input type="text" name="acct_holder-'.$i.'"></li>
</ul>
</p>
<p>Account Status:<br />
<input type="radio" value="Open" name="acctstatus-'.$i.'"> Open <br />
<input type="radio" value="Closed" name="acctstatus-'.$i.'"> Closed <br />
<input type="radio" value="Open_Paid_Off" name="acctstatus-'.$i.'"> Open but Paid Off <br />
<input type="radio" value="Closed_Paid_Off" name="acctstatus-'.$i.'"> Closed and Paid Off <br />
<input type="radio" value="Open_Suspended" name="acctstatus-'.$i.'"> Open but Suspended (non charging)<br />
</p>
</fieldset>
';
}
$form_block .='
<input type="hidden" name="toCheck" value="toCheck">
<input type="submit" name="accounts" value="Add New Accounts">
</form>
';
}
}
?>