douji6735 2013-07-23 18:48
浏览 9
已采纳

多功能按钮

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 .=   ' &nbsp; &nbsp; &nbsp; <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 .=   ' &nbsp; &nbsp; &nbsp; <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";
  • 写回答

2条回答 默认 最新

  • dongshi1934 2013-07-23 18:54
    关注

    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 .=   ' &nbsp; &nbsp; &nbsp; <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 ;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)