Form not being posted when a file is attached (xamp localhost) - php

I have a strange issue where a form is posted correctly when the file input is empty, but nothing is posted when I add a file.
My html:
<form method="post" action="create_product.php" enctype="multipart/form-data">
<?php echo display_error(); ?>
<div class="input-groep">
Homepage
<label>Product naam</label>
<input type="text" name="product_naam" value="<?php echo $product_naam; ?>" autocomplete="off">
</div>
<div class="input-groep">
<label>Beschrijving</label>
<input type="text" name="beschrijving" value="<?php echo $beschrijving; ?>" autocomplete="off">
</div>
<div class="input-groep">
<label>Prijs</label>
<input type="text" name="prijs" value="<?php echo $prijs; ?>" autocomplete="off">
</div>
<div class="input-groep">
<label>Afbeelding</label>
<input type="file" name="afbeelding" accept=".jpg,.jpeg,.png" autocomplete="off">
</div>
<div class="input-groep">
<button type="submit" class="homeknopdonker" name="register_product"> + Maak product aan</button>
Terug naar producten
</div>
</form>
When I submit the form without any values, I can see in my network tab the following:
product_naam:
beschrijving:
prijs:
afbeelding: (binary)
Above data is inside Form Data
However if I attach a file (small image) to the afbeelding input (file) the Form Data dissapears entirely from my network tab when I post it. The paramaters are nowhere to be seen and I get no errors when I turn on error_reporting.
What could be causing this?

Related

Why I can't update the record in codeigniter?

I am getting this error,
A PHP Error was encountered
Severity: Notice
Message: Trying to get property 'post_title' of non-object.
I cannot get the form inputs to print on the page and cannot update. Please help!
So, I have tried to update each record and only artist users are able to do that. But I cannot figure out how to show the individual post on the form page. The records saves correctly and deletes but cannot update them.
Controller
function editpost($post_id)//Edit post page
{
if (!$this->session->Role =='member,artist')
{
redirect(base_url() . 'login');
}
$data['success'] = 0;
if( !empty($this->input->post('post_title')) ) {
$data['post_title'] = $this->input->post('post_title');
$data['post'] = $this->input->post('post');
$data['active'] = 1;
/* >> file attach */
View
<form action="<?= base_url()?>starter/editpost/" method="post" class="justify-
content-center" enctype='multipart/form-data'>
<div class="form-group">
<label class="sr-only">Title</label>
<input type="text" class="form-control" placeholder="Title"
name="post_title" value="<?php echo $post->post_title; ?>">
</div>
<div class="form-group">
<label class="sr-only">Description</label>
<textarea class="form-control" placeholder="Describe it" name="post" ><?
php echo $post->post; ?></textarea>
</div>
<div class="row py-4">
<div class="col-lg-6 mx-auto">
<!-- Upload image input-->
<!-- File Button -->
<div class="col-md-5">
<input name="main_img[]" type="file" accept="image/x-png,image/gif,image/jpeg">
</div>
<br>
<br>
<p style="padding-top: 15px"><span> </span><input class="submit" type="submit" name="update"
value="Publish" /></p>
</form>
use direct the variable because you are passing just values which you are posting from form.
//like :
//for post_title
<input type="text" class="form-control" placeholder="Title"
name="post_title" value="<?php echo $post_title; ?>">
// for description
textarea class="form-control" placeholder="Describe it" name="post" ><?
php echo $post; ?></textarea>
You don't need to pass the post data in controller you can get post data anywhere
<input type="text" class="form-control" placeholder="Title" name="post_title" value="<?php echo ($this->input->post('post_title')!='')?$this->input->post('post_title'):''; ?>">

How can I make sure a user either inserted a description or file before form submission?

i have a foreach row that displays the "message icon" (i dont think it has anything to do with the form since the form is outside the loop:
enter image description here
which displays a chat form that you can either type a chat or send an attachment:
enter image description here
How can i make one of them required before submission? I tried through multiple JQuery ways but because they are in a for loop and each of them do not have a special id, its not working. any help please? I just need it to show an alert
Here is my code for the form:
<form method="post"action="<?php echo base_url();?>form_support_chat" enctype="multipart/form-data" class="ticket-reply-form">
<div class="row">
<div class="col-xs-12">
<div class="chat-left">
<input type="text" name="message" placeholder="Type Message ..." class="form-control" autocomplete="off">
<input type="hidden" name="cst_id" value="<?php echo $cst_id; ?>">
<input type="hidden" name="arch_ticket" value="<?php echo $arch_ticket; ?>">
<input type="hidden" name="ticket_number" value="<?php echo $ticket_number?>">
</div>
<div class="chat-right">
<label>
<img src="<?php echo base_url();?>/assest/icon-img/paperclip.png" class="ic_img" >
<input type="file" name="file" class="form-control" style="display:none;" id="hidden_upload_file_chatting">
</label>
<button type="submit" class="btn btn-flat" name="reply" value="reply" >Reply</button>
<button type="button" class="btn btn-flat" data-dismiss="modal" style="margin-left: 10px !important;">Close</button>
<span id="_showName"></span>
</div>
</div>
</div>
</form>
Simply use html5's required value
<input name="cst_id" value="<?php echo $cst_id; ?>" required>
or
<input name="cst_id" value="<?php echo $cst_id; ?>" required="true">
update
Using jQuery, add id value to each input
$(document).ready(function() {
if( $('#input1').valid() || $('#input2').valid(); ):
console.log("Success");
endif;
});

Update SESSION variable

I have the following code in index.php:
<div class="done">
<b>Thank you<?php
echo $_SESSION['session_vname']." ";
echo $_SESSION['session_lname']."! </b><br><br>Email: ";
echo $_SESSION['session_email']."<br> Status: ";
echo $_SESSION['session_status']."<br>";
?>
</div>
and
<div class="form">
<form method="post" action="process.php">
<div class="element">
<label>First Name</label>
<input type="text" name="vname" class="text" />
</div>
<div class="element">
<label>Last Name</label>
<input type="text" name="lname" class="text" />
</div>
<div class="element">
<label>Email</label>
<input type="text" name="email" class="text" />
</div>
<div class="element">
<label>Status</label>
<input type="text" name="status" class="text" />
</div>
<div class="element">
<input type="submit" id="submit"/>
<div class="loading"></div>
</div>
</form>
</div>
I execute the form with an ajax submit so the index.php gets no refresh. When finished
gets a fadeOut and a fadeIn.
This works fine except for the following part:
When div class="form" is shown, it shows the session variable from the form before the last submit.
Example:
first input: session_vname = testa
first output $_SESSION['session_vname'] = nothing
second input: session_vname = overflow
second output $_SESSION['session_vname'] = testa
So finally the question:
How can I force the to update the session variables after form submitting also index.php is not reloaded?
PHP code is executed on server side, before the page is shown to the viewer. That means you need to update static elements with JavaScript if you don't want to refresh the whole page.
You cant update server side php sessions using javascript, you should be using cookies for that type of functionality

Form Submit without Refreshing using Plugin (malsup)

I just created a form submit without refreshing using this plugin : http://malsup.github.com/jquery.form.js
The simple example can be seen at
http://jquery.malsup.com/form/
I don't what I was doing, it was worked fine before until I modified something that I don't remember.
When I click SAVE, it should be processed on the background and it should stay on the same page. But now, it doesn't and it redirect me to the action page (process-001.php)
I created another page using the same method, and it works just fine.
Can you see if I'm doing it wrong?
Here is the form :
<div id="submit-form">
<form action="web-block/forms/process-001.php" id="select-block" class="general-form" method="post" enctype="multipart/form-data">
<div class="input-wrap">
<input class="clearme" name="Headline" value="<?php echo $Headline;?>" id="headline"/>
</div>
<div class="input-wrap">
<textarea class="clearme" name="Sub-Headline" id="subheadline"><?php echo $SubHeadline ;?></textarea>
</div>
<label>Bottom Left Image</label>
<div class="up-mask">
<span class="file-wrapper">
<input type="file" name="Pics" class="photo" id="pics" />
<span class="button">
<span class="default-txt">Upload Photo</span>
</span>
</span>
</div><!-- .up-mask -->
<input type="hidden" name="Key" id="Key" value="<?php echo $Key;?>"/>
<input type="submit" class="submit-btn" value="SAVE" />
<span class="save-notice">Your changed has been saved!</span>
</form>
</div>
The Javascript :
<script>
// wait for the DOM to be loaded
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$('#select-block').ajaxForm(function() {
alert("Thank you for your comment!");
});
});
</script>

submit form data into iframe via post [file upload]

UGH.
Hi.
I have a form. I'd like to know how/if I could submit this form to an iFrame that has the page that will handle the file upload/naming.
If I try even something simple like post an input/text to the form, nothing happens (the handler is set to echo the $_POST). I have tried setting the iframe name/id et. al. and setting the form target to the respective iframe name/id. When I hit submit, the iframe just sits there like a dummy. WTF am I doing wrong?
Thx.
<form action="/clients/testAddTrans/<?=$clientID?>" id="reportEdit" class="EditName" method="POST" target="transFrame">
<div class="inputDiv">
<span class="inputLabel">Description:</span>
<span class="textInput">
<input type="text" id="transDesc" name="transDesc" value="" size="40" class=""/>
</span>
</div>
<div class="inputDiv">
<span class="inputLabel">Date:</span>
<span class="textInput">
<input type="text" id="date" name="transDate" value="" size="40" class=""/>
</span>
</div>
<div class="inputDiv">
<span class="inputLabel">File:</span>
<span class="textInput">
<input type="file" id="file" name="transFile" value="" size="40" class=""/>
</span>
</div>
<input name="name_id" type="hidden" value="<?=$itemid?>" />
<input type="submit" value="Submit" name="submit"/>
<input type="button" class="secondaryAction" onclick="hideOverDiv()" value="Close"/>
<div id="overDivNotice" class="overDivNotice" style="display:none"></div>
<iframe action="/clients/testAddTrans/<?=$clid?>" id="transFrame" name="transFrame" style=""></iframe>
</form>
Generated html via firebug:
<div class="content" id="overDivContent"><div class="inputDivContainer">
<fieldset class="inputOverDiv" id="tfa_Names">
<legend><b>Add Transmittal:</b></legend>
<div class="data"><form target="transFrame" method="POST" class="EditName" id="reportEdit" action="/clients/testAddTrans/fsdf1556"><div class="inputDiv"><span class="inputLabel">Description:</span><span class="textInput"><input type="text" class="" size="40" value="" name="transDesc" id="transDesc"/></span></div><div class="inputDiv"><span class="inputLabel">Date:</span><span class="textInput"><input type="text" class="" size="40" value="" name="transDate" id="date"/></span></div><div class="inputDiv"><span class="inputLabel">File:</span><span class="textInput"><input type="file" class="" size="40" value="" name="transFile" id="file"/></span></div><input type="hidden" value="121" name="name_id"/>
</form><br/>
<div align="center" class="actions" id="overDivActions">
<input type="submit" name="submit" value="Submit"/>
<input type="button" value="Close" onclick="hideOverDiv()" class="secondaryAction"/>
</div>
<div style="display: none;" class="overDivNotice" id="overDivNotice">
</div></div>
<iframe style="" name="transFrame" id="transFrame">tyh</iframe>
</fieldset>
</div></div>
I don't know why it is putting the </form> tag where it is.. It is supposed to be after the iframe, but whatever. Does that even matter? Is the iframe supposed to be inside the form?
Nice, I was wrong.. I found the problem.
First use html for write html;
With the code below works:
for 'testSubmitiFrame.html':
<form target="transFrame" method="POST" class="EditName" id="reportEdit" action="testSubmitiFrame.php">
<div class="content" id="overDivContent">
<div class="inputDivContainer">
<fieldset class="inputOverDiv" id="tfa_Names">
<legend><b>Add Transmittal:</b></legend>
<div class="data">
<div class="inputDiv">
<span class="inputLabel">Description:</span>
<span class="textInput"><input type="text" class="" size="40" value="" name="transDesc" id="transDesc"/></span>
</div>
<div class="inputDiv">
<span class="inputLabel">Date:</span>
<span class="textInput"><input type="text" class="" size="40" value="" name="transDate" id="date"/></span>
</div>
<div class="inputDiv">
<span class="inputLabel">File:</span>
<span class="textInput"><input type="file" class="" size="40" value="" name="transFile" id="file"/></span>
</div>
<input type="hidden" value="121" name="name_id"/>
<br/>
<div align="center" class="actions" id="overDivActions">
<input type="submit" name="submit" value="Submit"/>
<input type="button" value="Close" onclick="hideOverDiv()" class="secondaryAction"/>
</div>
<div style="display: none;" class="overDivNotice" id="overDivNotice"></div>
</div>
</fieldset>
</div>
</div>
</form>
<iframe style="" name="transFrame" id="transFrame">tyh</iframe>
for 'testSubmitiFrame.php':
<?php
var_dump($_POST);
?>
Your problem is html syntax. This works.
Apparently, a div or stupid fieldset tag being out of place was preventing the thing from working. I really gotta start checking my code before bothering you nice people.
Thanks anyway.
Your logic appears valid, can you setup a test page?
This page will do what you want, so you may want to look through it and see what may be different from what you are already doing:
http://www.anyexample.com/programming/php/php_ajax_example__asynchronous_file_upload.xml
Is the action in the html the php file that will do the processing?
I think it's because of these two lines:
echo "</div>";
echo "</div><br>
You're closing <div> with no opening tags. This is making Firefox close the <form> early - your submit button isn't inside your form, which is why it's not working.
The position of the iframe inside or outside the form doesn't matter - just make sure the rest of the HTML is valid and it should work.

Categories