开发者

HTML form only submits free of errors if every field is completed

The form below works regardless of whether or not all of the fields are filled out. This is what I want. However, if I leave some fields blank, I get some "Filename cannot be empty" errors. How can I eliminate those error messages?

echo '<form enctype="multipart/form-data" action="http://www...com/.../submit2a.php" method="post"> 
    <input type="hidden" value="'.$_SESSION['loginid'].'" name="uid">  

    <div class="submissiontitle"><label for="title">Blog Post Title:</label></div> 
    <div class="submissionfield"><input class="checkMax3" name="title" type="title" id="title" maxlength="80"></div>  

    <div class="texttitle"><label for="text1">Blog Post Text 1:</label></div> 
    <div class="textfield"><textarea class="checkMax" name="text1" type="comment" id="text1" maxlength="10000"></textarea></div>

    <div class="imagetitle"><label for="image1">Image 1:</label></div> 
    <div class="imagefield"><input type="file" name="image1" /></div>   

    <div class="hyperlinktitle"><label for="url1">Hyperlink 1:</label></div> 
    <div class="hyperlinkfield "><input name="url1" type="title" id="url1" maxlength="200"></div>

    <div class="texttitle2"><label for="text2">Blog Post Text 2:</label></div> 
    <div class="textfield2"><textarea class="checkMax" name="text2" type="comment" id="text2" maxlength="10000"></textarea></div>

    <div class="imagetitle2"><label for="image2">Image 2:</label></div> 
    <div class="imagefield2"><input type="file" name="image2" /></div>  

    <div class="hyperlinktitle2"><label for="url2">Hyperlink 2:</label></div> 
    <div class="hyperlinkfield2"><input name="url2" type="text" id="url2" maxlength="200"></div>

    <div class="texttitle3"><label for="text3">Blog Post Text 3:</label></div> 
    <div class="textfield3"><textarea class="checkMax" name="text3" type="comment" id="text3" maxlength="10000"></textarea></div>

    <div class="imagetitle3"><label for="image3">Image 3:</label></div> 
    <div class="imagefield3"><input type="file" name="image3" /></div>  

    <div class="hyperlinktitle3"><label for="url3">Hyperlink 3:</label></div> 
    <div class="hyperlinkfield3"><input name="url3" type="text" id="url3" maxlength="200"></div>

    <div class="texttitle4"><label for="text4">Blog Post Text 4:</label></div> 
    <div class="textfield4"><textarea class="checkMax" name="text4" type="comment" id="text4" maxlength="10000"></textarea></div>

    <div class="imagetitle4"><label for="image4">Image 4:</label></div> 
    <div class="imagefield4"><input type="file" name="image4" /></div>  

    <div class="hyperlinktitle4"><label for="url4">Hyperlink 4:</label></div> 
    <div class="hyperlinkfield4"><input name="url4" type="text" id="url4" maxlength="200"></div>

    <div class="submissionbutton"><input name="submit" type="submit" value="Submit"></div> 
</form>
';

EDIT: In case it might help, here is most of submit2a.php:

$remove_array = array('http://www.', 'http://', 'https://', 'https://www.', 'www.');

$uid = $_POST['uid'];

$title = $_POST['title'];

$text1 = $_POST['text1'];

$image1 = $_POST['image1'];

$image1 = $_FILES['image1'];

$url1 = $_POST['url1'];



$text2 = $_POST['text2'];

$image2 = $_POST['image2'];

$image2 = $_FILES['image2'];

$url2 = $_POST['url2'];



$text3 = $_POST['text3'];

$image3 = $_POST['image3'];

$image3 = $_FILES['image3'];

$url3 = $_POST['url3'];



$text4 = $_POST['text4'];

$image4 = $_POST['image4'];

$image4 = $_FILES['image4'];

$url4 = $_POST['url4'];







$cleanurl1 = str_replace($remove_array, "", $_POST['url1']);
$cleanurl1 = strtolower($cleanurl1);
$cleanurl1 = preg_replace('/\/$/','',$cleanurl1);
$cleanurl1 = stripslashes($cleanurl1);
$cleanurl1 = mysql_real_escape_string(trim($cleanurl1));

$cleanurl2 = str_replace($remove_array, "", $_POST['url2']);
$cleanurl2 = strtolower($cleanurl2);
$cleanurl2 = preg_replace('/\/$/','',$cleanurl2);
$cleanurl2 = stripslashes($cleanurl2);
$cleanurl2 = mysql_real_escape_string(trim($cleanurl2));


$cleanurl3 = str_replace($remove_array, "", $_POST['url3']);
$cleanurl3 = strtolower($cleanurl3);
$cleanurl3 = preg_replace('/\/$/','',$cleanurl3);
$cleanurl3 = stripslashes($cleanurl3);
$cleanurl3 = mysql_real_escape_string(trim($cleanurl3));

$cleanurl4 = str_replace($remove_array, "", $_POST['url4']);
$cleanurl4 = strtolower($cleanurl4);
$cleanurl4 = preg_replace('/\/$/','',$cleanurl4);
$cleanurl4 = stripslashes($cleanurl4);
$cleanurl4 = mysql_real_escape_string(trim($cleanurl4));



//$url = $_POST['url'];

//$subcheck = (isset($_POST['subcheck'])) ? 1 : 0;
$title = mysql_real_escape_string($title);
$title = stripslashes($title);
$slug = str_replace(' ', '-', $title);




echo '-'.$site1.'-';



$site1 = 'http://' . $cleanurl1;
$site2 = 'http://' . $cleanurl2;
$site3 = 'http://' . $cleanurl3;
$site4 = 'http://' . $cleanurl4;

$displayurl = parse_url($site1, PHP_URL_HOST);




    $query = sprintf("INSERT INTO submission VALUES (NULL, '$title', '$text1', '$text2', '$text3', '$text4', '$site1', '$site2', '$site3', '$site4', NULL)");


mysql_query($query);

        $id = (int) mysql_insert_id($db);   

$submissionid = $id;        



$info1 = getImageSize($image1['tmp_name']);

$queryimage1 = sprintf(
            "insert into images (NULL, submissionid, filename, mime_type, file_size, file_data)
                values ('%s', '%s', '%s', %d, '%s')",
            $submissionid,
            mysql_real_escape_string($image1['name']),
            mysql_real_escape_string($info1['mime']),
            $image1['size'],
            mysql_real_escape_string(
                file_get_contents($image1['tmp_name'])
            )
        )or die(mysql_error());





$info2 = getImageSize($image2['tmp_name']);

$queryimage2 = sprintf(
            "insert into images (NULL, ubmissionid, filename, mime_type, file_size, file_data)
                values ('%s', '%s', '%s', %d, '%s')",
            $submissionid,
            mysql_real_escape_string($image2['name']),
            mysql_real_escape_string($info2['mime']),
            $image2['size'],
            mysql_real_escape_string(
                file_get_contents($image2['tmp_name'])
            )
        )or die(mysql_error());     




 $info3 = getImageSize($image3['tmp_name']);

$queryimage3 = sprintf(
            "insert into images (NULL, submissionid, filename, mime_type, file_size, file_data)
                values ('%s', '%s', '%s', %d, '%s')",
            $submissionid,
            mysql_real_escape_string($i开发者_如何学Pythonmage3['name']),
            mysql_real_escape_string($info3['mime']),
            $image3['size'],
            mysql_real_escape_string(
                file_get_contents($image3['tmp_name'])
            )
        )or die(mysql_error());



 $info4 = getImageSize($image4['tmp_name']);

$queryimage4 = sprintf(
            "insert into images (NULL, submissionid, filename, mime_type, file_size, file_data)
                values ('%s', '%s', '%s', %d, '%s')",
            $submissionid,
            mysql_real_escape_string($image4['name']),
            mysql_real_escape_string($info4['mime']),
            $image4['size'],
            mysql_real_escape_string(
                file_get_contents($image4['tmp_name'])
            )
        )or die(mysql_error());     


//mysql_free_result($result);







header("Location: http://www...com/.../");
exit(); 


It's likely to be a problem with your database - if fields can be added even when empty, then make sure all the relevant fields in the database are set to allow NULL values.

The error you're getting back is a database error - the field isn't set to accept a null value (empty field from the form).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜