Jump to content

Retaining Customer entered data when form submission fails on bad data


AJ2

Recommended Posts

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.