AJ2 Posted September 11, 2011 Share Posted September 11, 2011 Am new here - looks like a great foru! I would sincerely appreciate any help anyone can give me. I have been trying to solve my problem for hours and I am not having any luck, so I thought I would post and see if anyone can help. I am very stuck and am not making much progress on this project, and I am certain the answer is very simple. I am constructing a form to collect data for a specialized purpose. The form and program actually work for its intended function, but I am trying to enhance the user experience by preventing customers from having to reenter all of their data should there be a problem with any of the data submitted. I have been able to do that with the contact form portion, but what I am having trouble with is the portion which has as many as 400 possible entries. So, in a nutshell, if the customers contact data is incomplete or in error, the form will ask them to return to the page and correct things. The previous data entered has been saved in the session and the input value will equal the previous entry. i.e. <tr> <td align="right" class="infoBox"><?php echo ENTRY_EMAIL_ADDRESS; ?></td> <td align=left><?php echo "<input type=text name='cemail' value=\"$cemail\" size=35 maxlength=35>" ?></td> </tr> Works perfectly, all well and good there. On the other 400 more or less entries, I am having a difficult time tweaking the string concatenation to work to achieve similar results. There are 4 columns each with $points entries asking for a dimension in either feet or inches. The <input name=> is one of ptaf,ptai,ptbf,ptbi, appended programatically with the corresponding row number or data point. i.e. "ptaf1", "ptai1", etc... This is produced by the example below and works perfectly also. <?php { $points=100; $i=1; while ($i <= $points) {echo ' <tr><td align="center" width="6"><b> ' .$i . '</b></td> <td align="right" NOWRAP>A' .$i . ' (ft) <input type="text" name="ptaf'.$i.'" size=4 maxlength=3> </td> <td align="right" NOWRAP>A' .$i . ' (in) <input type="text" name="ptai'.$i.'" size=4 maxlength=4> </td> <td align="right" NOWRAP>B' .$i . ' (ft) <input type="text" name="ptbf'.$i.'" size=4 maxlength=3> </td> <td align="right" NOWRAP>B' .$i . ' (in) <input type="text" name="ptbi'.$i.'" size=4 maxlength=4> </td> '; $i++; } } ?> I am trying to add <input value=$ptai.$i> for each field but as I mentioned I am not having any luck. It seems as if I have tried every combination imagineable, but still no luck. My head is spinning! The closest I seem to have gotten was with this: <td align="right" NOWRAP>A' .$i . ' (ft) <input type="text" size=6 maxlength=3 name="ptaf'.$i.'" value="' . "$ptaf" . $i . '" ></td> But line 17 for example returns this: <input type="text" value="17" name="ptaf17" maxlength="3" size="6"> To recap, I am trying to have the value set to whatever the customer may have entered previously. Again, I would most appreciate any help anyone can give me. If you need clarification on anything please let me know. Thanks AJ Quote Link to comment https://forums.phpfreaks.com/topic/246888-retaining-customer-entered-data-when-form-submission-fails-on-bad-data/ Share on other sites More sharing options...
Pikachu2000 Posted September 11, 2011 Share Posted September 11, 2011 Try this and see what you get. <td align="right" NOWRAP>A' .$i . ' (ft) <input type="text" size=6 maxlength=3 name="ptaf'.$i.'" value="'; echo !empty($_POST['ptaf' . $i]) ? $_POST['ptaf' . $i] : ''; echo '"></td>'; Quote Link to comment https://forums.phpfreaks.com/topic/246888-retaining-customer-entered-data-when-form-submission-fails-on-bad-data/#findComment-1267908 Share on other sites More sharing options...
AJ2 Posted September 11, 2011 Author Share Posted September 11, 2011 Thanks for the response, I appreciate your time. Unfortunately this didn't work for some reason. When I fill in the field I get the same value as before it is filled in., and I had to tweak it slightly to handle a couple of errors. So this is what I have now: $i=1; while ($i <= $points) {echo ' <tr><td align="center" width="6"><b> ' .$i . '</b></td> <td align="right" NOWRAP>A' .$i . ' (ft) <input type="text" size=6 maxlength=3 name="ptaf'.$i.'" value="';echo !empty($_POST['ptaf' . $i]) ? $_POST['ptaf' . $i] : ''; echo '"></td> <td align="right" NOWRAP>A' .$i . ' (ft) <input type="text" size=6 maxlength=3 name="ptaf'.$i.'" value="';echo !empty($_POST['ptai' . $i]) ? $_POST['ptai' . $i] : ''; echo '"></td> <td align="right" NOWRAP>A' .$i . ' (ft) <input type="text" size=6 maxlength=3 name="ptaf'.$i.'" value="';echo !empty($_POST['ptbf' . $i]) ? $_POST['ptbf' . $i] : ''; echo '"></td> <td align="right" NOWRAP>A' .$i . ' (ft) <input type="text" size=6 maxlength=3 name="ptaf'.$i.'" value="';echo !empty($_POST['ptbf' . $i]) ? $_POST['ptbi' . $i] : ''; echo '"></td> '; $i++; All of the value= return value="" like: <input type="text" value="" name="ptaf1" maxlength="3" size="6"> Any other thoughts? Thanks again for your time - it looks like we're getting closer. AJ Quote Link to comment https://forums.phpfreaks.com/topic/246888-retaining-customer-entered-data-when-form-submission-fails-on-bad-data/#findComment-1267945 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.