Page 3 of 3

Posted: Fri Nov 26, 2004 6:59 pm
by wadesmart
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.

Posted: Fri Nov 26, 2004 8:33 pm
by rehfeld
you keep retyping the code i gave you. your switching single and double quotes around and its causing you problems.


why not just folllow the format i gave you? whats wrong with it? it worked didnt it?

take a close look at how i use single and double quotes, in everything ive posted.

seriously, cut the code down to smaller parts and work on ONE thing at time. your going to drive yourself mad if you keep trying to change a bunch of things all at once that you dont yet understand

Posted: Sat Nov 27, 2004 1:01 pm
by wadesmart
Ok. Worked on this more after some sleep and got it to work with this:

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>

?>
I got the order of all the quotes correctly placed. I had to carefully re and reread your quote order posting earlier.

The problem I have is that its only posting one loop. If you use this with say two cars, only car number two will post.

Posted: Sat Nov 27, 2004 2:05 pm
by rehfeld
use $form_block .=

your doing $form_block =


also, stop doing this:

Code: Select all

&lt;input type = "text" name = "foo" value = "value"&gt;




do like this:

&lt;input type="text" name="foo" value="value"&gt;

some browsers may interpret that as a mistake,
and may correct it for you in a way that will break you code(like adding spaces into the value)


and when your posting your sample code, please make sure you are actually posting the code your currently using. i say this because theres no way possible the above code could even show 1 of the cars.

o the second form, you have
<input type="submit" name="submit2"

and then to display, you do
if(isset($_POST['submit3']))

where did submit3 come from? so try to be accurate, because people have no choice but to assume the code your posting is what your actually using.

also, its clear you have seperated the code into multiple pages, judgin by the action="page2a.php" stuff

it helps other help if you keep things as they are. either by specifying in the post that they are indeed sperate pages, or by using different blocks of code like so

Code: Select all

// code

Code: Select all

// more code

Code: Select all

// even more

to get the name of the file above the code block like i just did, do this


Posted: Sat Nov 27, 2004 2:26 pm
by wadesmart
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
and that code comes from this changed code script:

Code: 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>


?>
I noticed that this works fine when using three seperate pages but putting it together causes problems. Is that because of the way echo works compared to me using $form_block variable to hold code?

rehfield, I want to tell you I really appreciate you helping so much with this code. Sometimes books just dont work and tutorials and the best way is just working at it - and its with people like you who help - that people like me learn best.

Thanks.

Wade

Posted: Sat Nov 27, 2004 2:32 pm
by wadesmart
Ok. I changed the final block to this:

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 .='
    ';
  }
?>
and it works. !!

Posted: Sat Nov 27, 2004 3:24 pm
by rehfeld
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


the reason you get the error is because
$form_block .= 'foo';

is equivalent/shorthand to doing this

$form_block = $form_block.'foo';

so if form block is not yet defined, it will throw that warning at you(but it should still work normally, its just a warning that you code is _possibly_ "sloppy")

you can avoid this by putting defining the variable before you do any .=

Code: Select all

$form_block = ''; // define it

if(isset($_POST['submit']) || isset($_POST['submit2'])) {

kinda stuff. that way you define it and dont have to do it more than once.


just a question, what editor are you using to write your php? i would recomend getting one that has good syntax highlighting. it can help you spot errors as your writting the code, and in general just makes the code much more clear to you as your writing it.


and if echo worked but .= didnt, most likely what was happening is at somepoint after you did the .=
you reset the variable like $form_block = '';

Posted: Sat Nov 27, 2004 3:27 pm
by wadesmart
Im using SciTE Version 1.61 and I also use NoteTab Lite. I can see two windows side by side to work on the same document to make changes.

Ill play with it some more

Posted: Mon Nov 29, 2004 12:32 pm
by wadesmart
Ok. Im getting back to my project and applying everything that I have learned,

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: &nbsp; &nbsp; <input type="text" name='.$_POST['name-'.$j].'> </li>
							';
						} 
						else {
							$form_block .= '
								<li>Account Name: &nbsp; '.$_POST['name-'.$j].'</li>
							';
						}
						
						if(empty($_POST['number-'.$j])){
							$form_block .= '
								<li>Number: &nbsp; &nbsp; <input type="text" name='.$_POST['number-'.$j].'></li>
							';
						}
						else {
							$form_block .= '
								<li>Account Number: &nbsp; '.$_POST['number-'.$j].'</li>
							';
						}
				
						if(empty($_POST['telephone-'.$j])){
							$form_block .= '
								<li>Telephone: &nbsp; &nbsp; &nbsp; &nbsp; <input type="text" name='.$_POST['telephone-'.$j].'></li>
							';
						}
						else {
							$form_block .= '
								<li>Account Telephone: &nbsp; '.$_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: &nbsp; '.$_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: &nbsp; '.$_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>
          ';
  }
}
?>
I can submit the information from the second page to the third page, and I can see it when when I post is using

var_dump($_POST);
echo '<pre>';
print_r($_POST);

but, the loop doesnt run. The html part comes up but nothing else.

Posted: Mon Nov 29, 2004 1:38 pm
by rehfeld
echo $_POST['accounts']

to see if it contains a value

do the same for the others, cause i see your using a bunch of diff names for each diff loop

Posted: Mon Nov 29, 2004 2:37 pm
by wadesmart
What Im wanting to do is for each loop check a whole group of similar account names.

When I echo accounts i can see all the data that way but not on the web page.