Jump to content

Submitting form with more than one submit button


tivadarsubotica
Go to solution Solved by requinix,

Recommended Posts

Greeting,
I tried to simplify the script as much as possible to make it understandable and here is my question.

 

<?php
// DELETE FILES
$submit_file = $_POST['submit_file'];
echo $filename = $_POST['filename'];
if ($submit_file == '1') {
  unlink($filename);
} else {
}

if($reload == 2) {
	INSERT INTO..
}
else if ($reload > 2) {
	UPDATE ...
} else {}

?>

// BEGIN OF THE FORM
<form action="index.php?lg=<?php echo $lng; ?>&c=new_document" method="post" enctype="multipart/form-data">

// INPUT TEKST AND OTHERS
<input type="text" class="form-control form-control-lg" style="width: 40%;" id="sn_text_page" name="sn_text_page" value="<?php echo $text_page; ?>">
<textarea id="sn_text_lead" name="sn_text_lead" class="form-control font-weight-bold" rows="3"><?php echo $text_lead; ?></textarea>

// SELECT FILES (MORE THAS ONE)
<input type="file" name="file[]" id="file" multiple>

// SUBMITTING BUTTON INSERT (UPDATE) DATABASE
<button type="submit" name="submit_usertype" value="1" class="btn btn-primary"><?php echo $submit_button; ?></button>
<input type="hidden" name="sn_text_id" value="<?php echo $text_id; ?>">
<input type="hidden" name="reload" value="<?php echo $reload; ?>">

// LOADING FILES (IMAGES)
<?php
$files = glob('./tekstovi/' . $user_txt_year . '/' . $user_txt_nr . '/' . $text_page . '/' . $user_txt_year . '_' . $user_txt_nr . '_' . $text_nr . '_' . $text_page . '_img_' . '*.{doc,docx,odt,pdf,jpg,JPG,jpeg,png,gif,psd,eps,ai,tiff,tif}', GLOB_BRACE);
for ($i = 0; $i < count($files); $i++) {
  $image = $files[$i];
 ?>
<div class="col p-3">
<?php

  if ($reload == '1') {
  } else if ($reload > '1') {
    echo '<img class="img-fluid img-thumbnail shadow" src="' . $image . '" alt="" />' . '<small class="font-weight-bold">' . basename($image) . '</small><br /><br />';

?>
// DELETE ONE SELECTED FILE
<button type="submit" name="submit_file" value="1" class="btn btn-danger"><?php echo $list_document_button_title_delete; ?></button>
<input type="hidden" name="filename" value="<?php echo $image; ?>">
<input type="hidden" name="sn_text_id" value="<?php echo $text_id; ?>">
</div>
<?php }}?>
</div>

</form> // END OF FORM

I would like to delete the file I selected with "submit_file" and at the same time input the texts with UPDATE.
Thanks in advance,
T

(If I wasn't clear, ask. Thanks again.)

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.