paulnaj;10920179 wrote:

suppose someone gives up halfway? Half a 'data-set' is no good at all, and you now need some other way to clean the data.

Paul

You couldn't be more correct, I'm an idiot for not thinking of that!

I guess the burn of starting over goes with the territory of of being a newbie again. I don't code much (yet), but have been a Linux sys admin many years now.

I do understand your time is valuable but I simply cannot turn down your offer of a push in the right direction, no matter when you find time, it will be greatly appreciated. I've just started a long weekend holiday and will keep an eye out for your return and Paul thanks again.

Hooah!
Aaron

    Ok Aaron,

    Will get back as soon as I can - in the meantime, post up the tables you're using - the create SQL for each table would be good.

    Paul.

      Hi Aaron,

      I can't reach the earlier links you posted - now need authorization - can you post up the text files (the contact page, the srv page and the insertsrv page).

      Paul.

        Not too keen on passing out my email and I have PM turned off ... I much prefer to do everything on the board - helps other people that way.

        I only really need these to help me along - they're not crucial. If you can post them up then just save the php as txt files and attach them to a reply. Any sensitive details removed, of course.

        Paul.

          Hi Aaron,

          Thought it simplest to try the hidden-field method first - no new methods here.

          Here's a draft of the srv.awd page ... I've put some comments in for explanation, but see how you get ...

          <?php
          // Def Constant
          define( 'parentFile' , 1 );
          include('common.php');
          // Clean data input
          if (get_magic_quotes_gpc()){
           $_GET = array_map('stripslashes', $_GET);
           $_POST = array_map('stripslashes', $_POST);
           $_COOKIE = array_map('stripslashes', $_COOKIE);
          }
          
          // We'll use these to keep the hidden fields up to date
          // I'm assuming here that an incomplete form will NOT be sent here
          $GLOBALS['contact_fields'] = array('Name', 'Phone', 'Email', 'Unit', 'Deployed', 'Locale', 'Authorized', 'AppRank', 'AppPosition');
          
          if(isset($_POST['peoplereg'])){
          	// Set stepnum to 1
          	$_POST['stepnum'] = 1;
          } else {
          	$_POST['stepnum']++;
          }
          //Get count of all available items - Item A, Item B...
          $itemCount = getItemCount(); //
          
          //On the last step, the form should post to insert page (that page will send to thankyou)
          if($_POST['stepnum'] == $itemCount){
          	$frmaction = "insertsrv.awd";
          } else {
          	$frmaction = "srv.awd";
          }
          ?>
          <link rel="stylesheet" type="text/css" href="style.css" />
          <style type="text/css">
            .errFld {border: 1px solid #F00; }
            .errMsg { color: #C33; }
          </style>
          <script type="text/javascript" src="wforms.js"></script>
          <div id="soldier_left"></div>
          <div id="soldier_right"></div>
          <div>
          <div class="headr">
          <img src="images/headr.png" /><br>
          </div>
          
          <div class="container">
          <div class="bodyDiv">
          <div class="w745">
          <div class="txtDiv">
          <div class="survTitleDiv">
          <p class="survTitle">Item&nbsp;#<?php echo $_POST['stepnum']?>&nbsp;-&nbsp;<b><?php echo getItemName($_POST['stepnum']); ?></b></p>
          </div>
          <div class="survcontent"><div class="content">
          <form method="post" action="<?php echo $frmaction; ?>">
          	<input type="hidden" name="stepnum" value="<?php echo $_POST['stepnum']; ?>">
          <?php
          foreach($GLOBALS['contact_fields'] as $field_name){
          	// Here we use the array to echo out all the contact details in hidden fields
          ?>
          	<input type="hidden" name="<?php echo $field_name; ?>" value="<?php echo $_POST[$field_name]; ?>">
          <?php
          }
          if($_POST['stepnum'] > 1){
          	// Here we print out all previous answers
          	for($i = 1; $i <= $_POST['stepnum']; $i++){
          ?>
          	<input type="hidden" name="disposition_<?php echo $i; ?>" value="<?php echo $_POST['disposition_'.$i]; ?>">
          	<input type="hidden" name="band_<?php echo $i; ?>" value="<?php echo $_POST['band_'.$i]; ?>">
          <?php
          }
          ?>
          
          <div class="imgHold"><img src="<?php echo getItemImg($_POST['stepnum']); ?>"/></div>
          <br />
          <div class="desc"><b>Description:</b><br /><?php echo getItemDesc($_POST['stepnum']); ?></div>
          <br />
          <b>Choose your disposition:</b><br />
          <select name="disposition_<?php echo $_POST['stepnum']; ?>" class="validate-integer required btn">
          	<option selected="selected" value="X">Select one...</option>
          	<option value="1" class="switch-a">AP (Acquisition Program)</option>
          	<option value="2" class="switch-a">Sustain</option>
          	<option value="3">Terminate</option>
          	<option value="4">No Response</option>
          </select>
          
          <div class="itemchoice-E" id="itemchoice-E"></div>
          <div class="offstate-a">
          	<b>Please choose a retention band:</b>
          	<br />
          	<select name="band_<?php echo $_POST['stepnum']; ?>" class="validate-integer required btn">
          		<option selected="selected" value="X">Select One...</option>
          		<option value="1">Top Third: Must retain</option>
          		<option value="2">Middle Third: A good choice for retention</option>
          		<option value="3">Bottom Third: Optional choice for retention</option>
          	</select>
          </div>
          <div class="band-E"></div>
          <br />
          <span id="submitbutton" class="subbtn"><input class="next" type="submit" name="basicsurveysubmit" value="Next &gt;"></span>
          </form>
          </div></div>
          
          <div class="footr" align='center'><img src='images/awd_100.png' /></div>
          
          </div></div>
          
          </div>
          </div>
          <?php
          echo '<div class="dateDiv"><div class="date">';
          echo "Asymmetric Warfare Division (AWD)<br>Army Capabilities Integration Center (ARCIC) TRADOC<br>92 Patch Road, Bldg 270<br>Fort Monroe, VA 23651<br>";
          echo date(DATE_COOKIE);
          //echo date('l jS \of F Y h:i:s A') . " UTC";
          echo '</div></div>';
          
          ?>
          </div>
          

          Then, here's a draft insertsrv.awd page (no MySQL here, but we can finish this bit later.

          <?php
          
          // Do all of the MySQL insertions in this page
          
          // But before you even start on that code, check that ALL the data
          // is been collected correctly
          echo '<pre>'; var_dump($_POST); echo '</pre>';
          
          // Afterwards, head off to ...
          header('Location: thankyou.awd');
          ?>

          See how you get on with this. There weel could be typo's in here but I think the logic's correct - haven't got enough time to test it with your data.

          Paul

          PS. What kind of site is this again - lookks a buit scary :xbones:

            Hi Aaron,

            Just thought I'd mention ... comment out the header('Location: ') line in insertsrv.awd at this stage so you can see the data from the whole process in the browser (var_dump).

            P.

            (For some reason I can't edit the post a second time)

              Paul,

              Thank you!

              I'm going to start some coffee now and then get this code integrated.
              I'll let you know how it goes.

              A million thanks,
              Aaron

                Got the two pages re-factored.

                Kept getting unexpected $end on srv.awd so I had to add two brackets }

                The srv works, the items get rotated through but the printed array on submit doesn't look right. I'm wondering if my brackets were wrong.

                EDIT: The Array looks correct now.

                I have copied awd.srv as awd.txt and insertsrv.awd as insertsrv.txt

                Oh and it's not really that scary, it will be on a TOP SECRET non internet attached Department of Defense network once it's working as intended though. 🙂

                If you get a minute take a run through the survey to see the array results.

                mmmm coffee c[_]

                Best!
                Aaron

                  Hi Aaron,

                  Just ran through the survey - looking good - here's the results I got (just cycling through the options).

                  array(21) {
                    ["stepnum"]=>		string(1) "5"
                    ["Name"]=>		string(4) "name"
                    ["Phone"]=>		string(5) "phone"
                    ["Email"]=>		string(15) "email@email.com"
                    ["Unit"]=>		string(4) "unit"
                    ["Deployed"]=>	string(1) "Y"
                    ["Locale"]=>		string(6) "locale"
                    ["Authorized"]=>	string(4) "auth"
                    ["AppRank"]=> 	string(4) "rank"
                    ["AppPosition"]=>	string(4) "unit"
                    ["disposition_1"]=>	string(1) "1"
                    ["band_1"]=>		string(1) "1"
                    ["disposition_2"]=>	string(1) "2"
                    ["band_2"]=>		string(1) "2"
                    ["disposition_3"]=>	string(1) "3"
                    ["band_3"]=>		string(0) ""
                    ["disposition_4"]=>	string(1) "4"
                    ["band_4"]=>		string(0) ""
                    ["disposition_5"]=>	string(1) "1"
                    ["band_5"]=>		string(1) "1"
                    ["basicsurveysubmit"]=>string(6) "Next >"
                  }

                  I did notice that on some of the pages the 2nd select box didn't appear but that may have been due to what I selected in the first box (see 'band_3" and "band_4").

                  Paul.

                    yep that's intended on the retention band (second selection) only needed when disposition is 1 or 2.

                    I noticed the phone field in contact allowed you to enter alpha, I'll have to go change that.

                    I dare say I should be able to get this data put into the DB at this point.

                    edit: On second thought I would love to see what insertsrv is supposed to look like, haha I'm sure to take all day figuring it out.

                    One small question regarding the interpolated php with html.

                    I used tags like value=<?=$stepnum?>

                    You used tags like value=<?php echo $_POST['stepnum']; ?>

                    The echo, is that more efficient?

                    Is it because the $_POST variable was used and not a script generated one?

                    Or just plain ol' personal preference?

                    I can't thank you enough for sharing your knowledge with me.
                    This has been a great learning experience for me.

                    Respectfully,
                    Aaron

                      Hi aaron,

                      Glad to help!

                      Re the tags, I always use single-quotes to enclose strings UNLESS I have to use double-quotes (embedding newlines for example) ....

                      // -- good for HTML 
                      echo '<div class="fred">';
                      // ... is easier to read than ...
                      echo "<div class=\"fred\">";
                      
                      // -- doesn't allow variable embedding so ...
                      echo '<div class="'.$my_class.'">';
                      //... is easier to read than ... 
                      echo "<div class=\"$my_class\">";
                      

                      The form <?=$stepnum?> is now deprecated - some servers will not interpret this correctly - best use the long form these days.

                      $stepnum will only contain the value of $POST['stepnum'] if the server has 'register globals' turned on. This is now considered a security risk so most servers have globals turned off. That means you should always use $POST['stepnum'] explicitly.

                      Also, when you come back after six months to adjust something, it'll be easier to read.

                      Hope that helps.

                      Paul.

                      PS Just noticed the comment re inserting ... it's pretty much what you have done already (especially where you inserted the contact data and the survey). The only bit you'll have to do is cycle through bands/dispositions and insert each in turn.

                        ignore me - paul got it faster and better

                          Write a Reply...