Edit text field only on text and document form

I have a form that I would like to edit. Looks like this:

What I would like to accomplish is change the Title or Date without uploading a new document and not losing the document from the table row when I do upload the Title or date.

As it is now, I have to upload all fields in the form or else the data will not be entered into the database.

For example: If I changes the Title only, I would like the date to stay the same, which it probably would because there is a value in the field.
So the hardest part of this for me is…“How do I edit the form without having to upload the original document or a new document so I can
get the updated Title into the database without loosing the current document?”

Here is the code I’m working with.
edit.php
[php]<?php
$title = ‘Edit Meeting Minutes’;

$page_description = “Add description in here.”;

$thisPage=“admin”;

include_once($_SERVER[‘DOCUMENT_ROOT’]."/header.php");

if(isset($_FILES[‘file_name’])){

$errors = array();



if($_FILES['file_name']['error'] === 4){

    $errors[] = 'Please, select a file.';

} else {

    try {

        $uploader = new DocUploader($_FILES['file_name']);

        $uploader->setTarget("../../owners/uploads/minutes/");

        $uploader->upload();

        

        if($uploader->errors()){

            $errors = array_merge($errors, $uploader->errors());

        }

    } catch(UploaderException $e){

        $errors[] = $e->getMessage();

    }

}

}

?>

//HTML etc…

<?php
    if(isset($_FILES['file_name'])){

        if(!empty($errors)){

            ?>
	<div class="error"> <b>Uh oh!</b><br />
			<?php echo '- ', implode('<br />- ', $errors), '<br />'; ?> </div>
	<?php

        } else {

			
			$editminutes = DB::getInstance()->update('minutes', array(
            	'title_name'    => Input::get('title_name'),
            	'meeting_date' => Input::get('meeting_date'),
            	'file_name'     => str_replace('../../owners/uploads/minutes/','',$uploader->getFile())
            )); 

            echo '<b>Success!</b><br />';

            echo "The file has been added to meeting minutes.<br />

Post another meeting minute.
";

        }

    }

$id = (int)$_GET[‘id’];
$minutes = DB::getInstance()->query(“SELECT id, meeting_date,title_name,file_name FROM minutes WHERE ID = $id”);

foreach($minutes->results() as $min){

    ?>
	<br />
	<form enctype="multipart/form-data"  method="POST">
			<input type="hidden" name="id" style="width: 100%" value="<?php echo escape ($min->id); ?>">
			<div class="grid_12 botspacer60 "> Edit Meeting Minutes Title:
					<input type="text" name="title_name" value="<?php echo escape ($min->title_name); ?>">
					<br />
					<br />
					Edit Meeting Minutes Date:
					<input type="date" name="meeting_date" value="<?php echo escape ($min->meeting_date); ?>">
					<br />
					<br />
					Upload New Meeting Minutes Document:<br>
					Current file: <a href="http://<?php echo $_SERVER['SERVER_NAME']; ?>/owners/uploads/minutes/<?php echo escape ($min->file_name); ?>" target="_blank"><?php echo escape ($min->file_name); ?></a><br>
					<br>
					<input type="file" name="file_name"/>
					<br />
					<br />
					<input type="submit" value="Update">
					<input type="button" value="Cancel" onclick="window.location = '/admin'">
			</div>
	</form>
	<?php 

}
?>

[/php]

Any help would be appreciated.
Thanks!

Look into doing this in PHP, JavaScript (I prefer using jQuery) and AJAX for real time editing, using straight php will cause the page to reload. Though I guess you could use $_SESSION though in my opinion that tends to get messy and in my opinion slightly higher risk of a security breach.

Or, just post the values to the database using UPDATE. When you show the form, load the current values and let the user change whatever they want and use the query to store the new values.

If you want to change the date or title, you already have the rest stored. Just load them all into the fields and save the new values if they are changed.

Sponsor our Newsletter | Privacy Policy | Terms of Service