I have a problem posting text fields and uploading a picture at the same time, at the moment I can either upload a picture or post the text fields. How can I post it all at the same time using one button?
$photo_form = '<form id="photo_form" enctype="multipart/form-data" method="post" action="php_parsers/status_system.php">';
$photo_form .= '<select name="gallery" required>';
$photo_form .= '<option value="Cover">Cover</option>';
$photo_form .= '</select>';
$photo_form .= ' <b>Browse:</b> ';
$photo_form .= '<input type="file" name="photo" accept="image/*" required>';
$photo_form .= '<p><input type="submit" value="Upload"></p>';
$photo_form .= '</form>';
$status_ui = "";
$status_ui = '<div><textarea id="statustext" onkeyup="statusMax(this,500)" placeholder="Description field"></textarea>';
$status_ui .= $photo_form;
$status_ui .= '<textarea id="statustext2" onkeyup="statusMax(this,200)" placeholder="Description field 2."></textarea></div>';
$status_ui .= '<button id="statusBtn" onclick="postToStatus(\'status_post\',\'a\',\''.$u.'\',\'statustext\',\'statustext2\')">Post</button>';
To Maximus2012
$status_ui = "";
$status_ui .= '<div><textarea id="statustext" name="statustext" onkeyup="statusMax(this,500)" placeholder="Description field"></textarea>';
$status_ui .= '<textarea id="statustext2" name="statustext2" onkeyup="statusMax(this,200)" placeholder="Description field 2."></textarea></div>';
$photo_form = '<form id="photo_form" enctype="multipart/form-data" method="post" action="php_parsers/status_system.php">';
$photo_form .= '<select name="gallery" required>';
$photo_form .= '<option value="Cover">Cover</option>';
$photo_form .= '</select>';
$photo_form .= ' <b>Browse:</b> ';
$photo_form .= '<input type="file" name="photo" accept="image/*" required>';
$photo_form .= $status_ui ;
$photo_form .= '<p><input type="submit" value="Upload"></p>';
$photo_form .= '</form>';
echo $photo_form ;
I can still only upload image with this code but when I use
$photo_form .= '<p><button id="statusBtn" onclick="postToStatus(\'status_post\',\'a\',\''.$u.'\',\'statustext\',\'statustext2\')">Post</button></p>';
instead of
$photo_form .= '<p><input type="submit" value="Upload"></p>';
everything is processed but text parts are insterted in one row and image in another.
This is my postToStatus function:
function postToStatus(action,type,user,ta,te){
var data = _(ta).value;
var data2= _(te).value;
if(data == "" && data2 == ""){
alert("Please fill in all fields");
return false;
}
I made some adjustments to my image parsing script so text and image are placed in the same row, since image is uploaded after text, instead of inserting filename into a new row script is now updating last row created by that user on his profile. Now I just need to prevent posting the form if any of the fields is blank.
$sql = "UPDATE status SET filename = '$db_file_name' WHERE author = '$log_username' && account_name = '$log_username' ORDER BY id DESC LIMIT 1";
Your text field and picture field are not part of same form. See if this works:
$status_ui = "";
$status_ui .= '<div><textarea id="statustext" name="statustext" onkeyup="statusMax(this,500)" placeholder="Description field"></textarea>';
$status_ui .= '<textarea id="statustext2" name="statustext2" onkeyup="statusMax(this,200)" placeholder="Description field 2."></textarea></div>';
$photo_form = '<form id="photo_form" enctype="multipart/form-data" method="post" action="php_parsers/status_system.php">';
$photo_form .= '<select name="gallery" required>';
$photo_form .= '<option value="Cover">Cover</option>';
$photo_form .= '</select>';
$photo_form .= ' <b>Browse:</b> ';
$photo_form .= '<input type="file" name="photo" accept="image/*" required>';
$photo_form .= $status_ui ;
$photo_form .= '<p><input type="submit" value="Upload"></p>';
$photo_form .= '</form>';
echo $photo_form ;
There are two options here. The first is to include ALL the information you want within the same form. That means that any field within that form will be "submitted".
This would look like (just combining $photo_form
and $status_ui
:
$photo_form = '<form id="photo_form" enctype="multipart/form-data" method="post" action="php_parsers/status_system.php">';
$photo_form .= '<select name="gallery" required>';
$photo_form .= '<option value="Cover">Cover</option>';
$photo_form .= '</select>';
$photo_form .= ' <b>Browse:</b> ';
$photo_form .= '<input type="file" name="photo" accept="image/*" required>';
$photo_form .= '<textarea id="statustext" onkeyup="statusMax(this,500)" placeholder="Description field"></textarea>';
$photo_form .= '<textarea id="statustext2" onkeyup="statusMax(this,200)" placeholder="Description field 2."></textarea>';
$photo_form .= '<p><input type="submit" value="Upload"></p>';
$photo_form .= '</form>';
However, this option will bypass the postToStatus()
that was happened with the statusBtn before.
The other option (which will still allow the call to postToStatus()
) you have is to do it through your javascript. You can use the javascript to grab the image inside the other form before the AJAX/POST/GET call that your postToStatus
function makes.