Keeping prepopulated information in textarea after errors & 1 more related issue

4 posts by 2 authors in: Forums > CMS Builder
Last Post: July 29, 2020   (RSS)

By gkornbluth - July 18, 2020 - edited: July 20, 2020

Hi All,

I have a text field in an update form on a multi record detail page that gets its record number from the end of the URL and using the _link : code in the list page to select the record for the detail page.

In this example, there are only 2 text box fields, ‘existing’ and pending’ in each record.

The textarea field in this form get pre-populated from the information in a field in the appropriate record.

1) The mysql_update stopped updating the record and I can’t figure out what I did.

2) If a submit is attempted, whether and errors and alerts are thrown or not, the textarea field loses it’s pre-populated (and potentially revised) information and is blank and I get the following 2 errors on the page;
Notice: Undefined variable: record in /home2/ngpymrmy/public_html/pollick/OK/updater17.php on line 41
and
Notice: Undefined variable: originRecord in /home2/ngpymrmy/public_html/pollick/OK/updater17.php on line 161.

Any thoughts on how I can eliminate the errors and keep the information showing after a submission error is thrown?

Thanks,

Jerry Kornbluth

Here’s the active code I’m using. (The complete page is attached)

At the top of the List page:

<?php if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); } ?>
<?php $userAuth = $CURRENT_USER['photo_album_notes_revision_authorization'] ?>
<?php
// load records from 'updater'
list($updaterRecords, $updaterMetaData) = getRecords(array(
'tableName' => 'updater',
'loadUploads' => true,
'allowSearch' => false,
'where' => 'photo_album_notes_revision_authorization = "'. $userAuth .'"' ,
));

?>

And the Link in the body:

<?php foreach ($updaterRecords as $record): ?>
<a href="http://pollick.net/OK/updater17.php?recNum=<?php echo $record['num'] ?>">http://pollick.net/OK/updater17.php?recNum=<?php echo $record['num'] ?></a>
<?php endforeach ?>

And at the top of the updater page:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php $recNum = $_REQUEST['recNum']; ?>
<?php include ("../_website_init.php");
// load record from 'updater'
list($updaterRecords, $updaterMetaData) = getRecords(array(
'tableName' => 'updater',
'where' => 'num = "'. $recNum .'"' ,
'loadUploads' => true,
'allowSearch' => false,
));
?>
<?php if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); } ?>
<?php
foreach ($updaterRecords as $record):
if ($record['num'] == $recNum ){


$originRecord = mysql_get('updater', $record['num']);
if (!empty( $originRecord['existing'] )) {
echo $originRecord['existing']; // for testing
}
if (!empty( $originRecord['pending'] )) {
echo $originRecord['pending']; // for testing
}

}

endforeach;
?>

<?php // prepopulate fields
if ( @!$_REQUEST['save'] && @!$_REQUEST['go']) {
foreach ($updaterRecords as $record):
foreach ($record as $name => $value):
if (array_key_exists($name, $_REQUEST)) { continue; }
$_REQUEST[$name] = $value;
endforeach;
endforeach;
}
?>
<?php $recNum =$record['num']; ?>

RECORD NUMBER = <?php echo $recNum ?>

<?php // error checking
if ( @$_REQUEST['save'] && @!$_REQUEST['go']) {
$errorsAndAlerts = "Remember, before you can update the 'Notes', you must check the check box above the 'Submit' button.";
}
?>
<?php // submit form if criteria are met
$sent = 0 ;
if ( @$_REQUEST['go'] && @$_REQUEST['save'] ){

$colsToValues = array();
$colsToValues['pending'] = $_REQUEST['pending'];
mysql_update('updater', $recNum, null, $colsToValues);
// on success
$errorsAndAlerts = "The revised 'notes' below have been submitted and are pending approval<br><br>To make further changes, correct the text, then Click/Tap the 'Submit' button again.";
$sent = 1;
}
?>

And the update form in the body:

<!-- UPDATE FORM -->
<?php if (@$errorsAndAlerts): ?>
<div class="navigation_font" style="color: #fea407; font-weight: bold; font-size: 1.3em;"><br />
<?php echo $errorsAndAlerts; ?><br />
</div>
<?php endif ?>
<br />
<?php if (@$errorsAndAlerts ==""):?>
<br />
<span class="navigation_font"> If it exists, the form will be populated with the existing 'Notes' information. Enter your changes and Click/Tap on 'Submit'</span><br />
<br />
<?php endif ?>
<form method="post" action="?">
<input type="hidden" name="save" value="1" />
<table border="0" cellspacing="0" cellpadding="2">
<?php if($sent==0):?>
<tr>
<td valign="top" class="navigation_font" style="font-size:1.3em">Existing Notes &nbsp; </td>
<td><textarea name="pending" class="navigation_font" style="font-size:1.2em; color:#000; background-color:#9f775f;" ROWS="20" COLS="150" />
<?php echo $originRecord['existing']; ?>
</textarea></td>
</tr>
<?php else :?>
<tr>
<td valign="top" class="navigation_font" style="font-size:1.3em"></td>
<td><textarea name="pending" class="navigation_font" style="font-size:1.2em; color:#000; background-color:#9f775f;" ROWS="20" COLS="150" />
<?php echo $originRecord['pending']; ?>
</textarea></td>
</tr>
<?php endif ?>
<tr>
<td colspan="2"><br>
<br>
<input type = "checkbox" id="go" name="go" value = "1" <?php checkedIf(1,
@$_REQUEST['go']);?> />
<span class="navigation_font">When you're ready to update, check this box and click
"Submit"</span></td>
</tr>
<tr>
<td colspan="2" align="center"><br />
<input class="button" type="submit" name="submit" value="Submit &gt;&gt;" /></td>
</tr>
</table>
</form>

<!-- END UPDATE FORM -->

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

updater17.php 7K

By gregThomas - July 28, 2020

Hey Jerry, sorry I've been slow to get back to you on this one. 

I think I've worked out the source of the issue, on line 146 the form starts that submits the updater record, but it doesn't include the record number. So when the form submits the page can no longer find the record it's supposed to be updating. 

If you change line 145 from this:

<form method="post" action="?">
  <input type="hidden" name="save" value="1" />
  <table border="0" cellspacing="0" cellpadding="2">

to this:

<form method="post" action="?">
  <input type="hidden" name="save" value="1" />
  <input type="hidden" name="recNum" value="<?php echo intval($recNum); ?>" />
  <table border="0" cellspacing="0" cellpadding="2">

Let me know if this resolves this issue.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gkornbluth - July 29, 2020

Hi Greg,

Thanks very much for catching that.

With a few more code changes the page seems to work now. 

Once I've finished adding the additional functionality, I'll post the result.

Best,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php