Jump to content

How can i insert no empty field condition to a (NEXT) Button


rudarel

Recommended Posts

Can Some One please help?

Hi i have this PHP upload form that someone created for me and i cannot find hem no more, it is currently made of one single page including customer's info
(name, address etc...) and!! the actual upload field and browse button where the customer can browse for a file on hes computer before uploading it, then last the (UPLOAD) button which check's to make sure at list one file was inserted in the upload field and all the customer's info fields are filled in. I would like to split this page in two, first part to contain only the customer's info(name, number etc) and then a (NEXT) button with hyperlink to the second part which will be the actual upload file form with the browse button and all that. I can use Microsoft-FrontPage to do cosmetics and cut this page in two but my question is: how can i insert this next button in to the PHP script so when the customer actually click's on it will check to make sure all the fields have been filled and if not to pup a message informing the customer he needs to fill in all the fields before he can proceed to the upload form.

PS: I attached a copy of the script hopping you can help and tell me how and where to add the necessary script in order for this NEXT button to work.
Thank's in advance
Rudarel. 
[code]<html>
<head>
<title>Process Uploaded File</title>
<style type="text/css">
table, p
{
font-family: Tahoma;
font-size: small;
}
input {
border: solid;
border-width: thin;
border-color: Gray;
font-family: Tahoma;
font-size: small;
}
textarea, select
{
border: solid;
border-color: Gray;
border-width: thin;
font-family: Tahoma;
font-size: small;
}

</style>
</head>
<body bgcolor="#A8BCEC">
<table width="746" align="center" cellpadding="0" cellspacing="0">
<tr align="center">
<td width="14"><img src="img/stsus.jpg"></td>
<td width="719"><img src="img/sus.jpg"></td>
<td width="13"><img src="img/drsus.jpg"></td>
</tr>
<tr valign="middle">
<td width="14" background="img/stanga.jpg"></td>
<td width "719" align="center">
<?php
function uploadfile($handler,$user_id,$target_dir) //uploads the file pointed by $handler to $target_dir
{
// if there was no file selected for upload, the function is terminated
if ($_FILES[$handler]['name']=='') return 0;
// replaces the spaces in the file names with underscores
$filename=str_replace(' ','_',basename($_FILES[$handler]['name']));
// establishes the name of the file on the disk
$target_path = $target_dir .$filename;
// attempts to upload the file
$success=move_uploaded_file($_FILES[$handler]['tmp_name'], $target_path);
// checks the succes of the upload attempt for the file
if($success) {
echo "<br>The file <b>". basename($_FILES[$handler]['name']). "</b> has been uploaded.";
// changes priveleges on the file
chmod($target_path, 0755);
// adds the file to database
$insert_data='INSERT INTO files(user_id,file) VALUES("'.$user_id.'","'.$filename.'")';
$qinsert=mysql_query($insert_data);
}
// error output, if necessary
else switch ($_FILES[$handler]['error']) {
case 1:
print '<p> The file <i>'. basename( $_FILES[$handler]['name']).'</i> is bigger than this PHP installation allows</p>';
break;
case 2:
print '<p> The file <i>'. basename( $_FILES[$handler]['name']).'</i> is bigger than this form allows</p>';
break;
case 3:
print '<p> Only part of the file <i>'. basename( $_FILES[$handler]['name']).'</i> was uploaded</p>';
break;
case 4:
print '<p> No file was uploaded</p>';
break;
}
return($success);
}
function check_personal_info() // checks if every personal info field has been completed
{
return ($_POST['fname']!='')&&($_POST['phone']!='')&&($_POST['email']);
}
function check_uploads() //checks if there is at least one upload field completed
{
$ckupld=0;
for ($i=1;$i<26;$i++) $ckupld=(($ckupld)or($_FILES['image'.$i]['name']!=''));
return $ckupld;
}
set_time_limit(0);
// initializes the control variable
$ok=1;
// checks the completion of the personal info and outputs errors if necessary
if (!(check_personal_info()))
{
echo('<font color="red"><b>Please fill in all the fields.</font></b><br><br>');
$ok=0;
}
//checks the completion of at least one upload field and output errors if necessary
if (!(check_uploads()))
{
echo('<font color="red"><b>Please include at least one file for upload.</font></b><br><br>');
$ok=0;
}
// procedes with operations if all is ok
if ($ok)
{
// database connection
include('connect.php');
// sets the location on the disk where the files will be placed
$target_dir = "./uploads/";
// converts all spaces in the name of the archive (zip) to underscores
$filename=str_replace(' ','_',basename($_FILES['archive']['name']));
// sets the file name&path for the archive (zip)
$target_path = $target_dir .$filename;
//initializes check of at least one upload
$did_smthg=0;
// add basic info from the user in the database
$insert_data='INSERT INTO users(fname,lname,adress,city,phone,email,comment,file,date,number,size) VALUES("'.$_POST['fname'].'","'.$_POST['lname'].'","'.$_POST['adress'].'","'.$_POST['city'].'","'.$_POST['phone'].'","'.$_POST['email'].'","'.$_POST['comment'].'","'.$filename.'",NOW()'.',"'.$_POST['number'].'","'.$_POST['size'].'")';
$qinsert=mysql_query($insert_data);
if (!$qinsert) die('serverul a luat muie cand executa '.$insert_data);
// extracting the id (autoincrement) of the inserted row
$get_id='SELECT MAX(`user_id`) FROM users';
$q_result=mysql_query($get_id);
$row=mysql_fetch_array($q_result, MYSQL_NUM);
$userid=$row[0];
// iterates the file upload procedure for 25 image files
for ($i=1;$i<26;$i++) if (uploadfile('image'.$i,$userid,$target_dir)) $did_smthg=1;
if (!$did_smthg)
{
mysql_query('DELETE FROM files WHERE user_id='.$userid);
echo ' <font color="red"><b>Your order has not been registered.</font></b><br><br>
<form>
<input type=button value="Back to upload form"
onCLick="history.back()">
</form>';
}
echo '<br><p align="center"><a href="./../index.html">Back to homepage</a></p>';
}
else echo ' <form>
<input type=button value="Back to upload form"
onCLick="history.back()">
</form>';
?>
</td>
<td width="13" background="img/dreapta.jpg"></td>
</tr>
<tr>
<td width="14"><img src="img/stjos.jpg" ></td>
<td width="719"><img src="img/jos.jpg"></td>
<td width="13"><img src="img/drjos.jpg"></td>
</tr>
</table>
</body>
</html>[/code]


Link to comment
Share on other sites

PHP could do this if you want to if-else it to death.  Or you could google some JavaScript that checks the form elements' values when the "onClick" event is triggered within the <input> tag for the submit button.  I'm sorry, but I'm not that familiar with JavaScript, or I'd post some code.
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.