Jump to content

Recommended Posts

I hope someone can help.

 

I have a form created in PHP. When someone does not fill the input box a message comes up "Please enter you First Name", see example below:

 

"/Check fname entered

if($_POST['fname'] == NULL && $message == NULL){ $message = 'Please enter your first name.';}"

 

I also have an image upload link with a browse button and want to have the same message come up, but showing "Please upload image". See the scrip below. How can I add this statement to it?

 

"//File Upload checks

if($message == NULL && $FILE_UPLOAD == 1 && $_FILES['user_file']['name'] != NULL){

if($_FILES['user_file']['size'] > (($FILE_UPLOAD_MAX*1024)*1024)){ $message = 'File is over '.$FILE_UPLOAD_MAX.' MB in size.';}

if($message == NULL && allowed_ext($FILE_UPLOADS_EXT,$_FILES['user_file']['name']) == false){$message = 'Invalid extension.';}

$new_filename = date("G_i_s_").$_FILES['user_file']['name'];}"

 

Can someone help please.

tk you

Link to comment
https://forums.phpfreaks.com/topic/53088-solved-php-form-scripting-help/
Share on other sites

your need to add the same thing but to the name of the file field

 

ie

<input name="uploadedfile" type="file" />

 

duplicate

if($_POST['fname'] == NULL && $message == NULL){ $message = 'Please enter your first name.';}"

and change fname to whatever the type file was ie: uploadedfile

if($_POST['uploadedfile'] == NULL && $message == NULL){ $message = 'Please enter your first name.';}"

of course change the message

 

hope that helps

Here is the code:

 

//If contact is being sent:
if($_POST['submit_id'] == 1){
//Check fname entered
if($_POST['fname'] == NULL){ $message = 'Please enter your first name.';}

//Check lname entered
if($_POST['lname'] == NULL && $message == NULL){ $message = 'Please enter your last name.';}

//Check business name entered
if($_POST['busname'] == NULL && $message == NULL){ $message = 'Please enter your business or organization name.';}

//Check address1 entered
if($_POST['address1'] == NULL && $message == NULL){ $message = 'Please enter a address.';}

//Check address2 entered
//if($_POST['address2'] == NULL && $message == NULL){ $message = 'Please enter a address.';}

//Check City entered
if($_POST['city'] == NULL && $message == NULL){ $message = 'Please enter your city.';}

//Check State entered
if($_POST['state'] == NULL && $message == NULL){ $message = 'Please enter your state.';}

//Check zip code entered
if($_POST['zip'] == NULL && $message == NULL){ $message = 'Please enter your zip code.';}

//Check home phone entered
if($_POST['hphone'] == NULL && $message == NULL){ $message = 'Please enter your home phone.';}

//check if email is enetered
if($message == NULL && is_valid_email($_POST['email']) == false ){ $message = 'Please enter a valid email.';}

//Check User web name entered
if($_POST['webname'] == NULL && $message == NULL){ $message = 'Please enter your web name.';}

//Check target amount entered
if($_POST['target'] == NULL && $message == NULL){ $message = 'Please enter your Fundraising target amount.';}

//check if message is entered
if($_POST['message_text'] == NULL && $message == NULL){ $message = 'Please enter a comment.';}

//check if image entered
//if($_POST['user_file'] == NULL && $message == NULL){ $message = 'Please enter your image profile.';}

//File Upload checks
if($message == NULL && $FILE_UPLOAD == 1 && $_FILES['user_file']['name'] != NULL){
	if($_FILES['user_file']['size'] > (($FILE_UPLOAD_MAX*1024)*1024)){ $message = 'File is over '.$FILE_UPLOAD_MAX.' MB in size.';}
	if($message == NULL && allowed_ext($FILE_UPLOADS_EXT,$_FILES['user_file']['name']) == false){$message = 'Invalid extension.';}
	$new_filename = date("G_i_s_").$_FILES['user_file']['name'];
}

//Image verificaiton checks
if($message == NULL && $IMAGE_VERIFICATION == 1){
	$te_co = hex2bin($_POST['hid_code']);
	$word_is = RC4($te_co,$IMAGE_VER_CODE);
	if($word_is != $_POST['confirm_image']){$message = 'Your verfication code is incorrect.';}
}
//End verifications, start processing
if($message == NULL){
	//Check if file upload is needed
	if($FILE_UPLOAD == 1 && $_FILES['user_file']['name'] != NULL){
		//Store file for keep and email
		move_uploaded_file($_FILES['user_file']['tmp_name'],$FILE_UPLOADS_DIR.$new_filename);
	}
	//compose admin/user message templates replaces
	$do_search = array(	'$+fname+$','$+lname+$','$+busname+$','$+address1+$','$+address2+$','$+city+$','$+state+$','$+zip+$','$+hphone+$','$+wphone+$','$+email+$','$+webname+$','$+target+$','$+message_text+$','$+note_text+$');
	$do_replace = array($_POST['fname'],$_POST['lname'],$_POST['busname'],$_POST['address1'],$_POST['address2'],$_POST['city'],$_POST['state'],$_POST['zip'],$_POST['hphone'],$_POST['wphone'],$_POST['email'],$_POST['webname'],$_POST['target'],$_POST['message_text'],$_POST['note_text']);


	//Send user email?
	if($SEND_THANKS == 1){
		$user_message = str_replace($do_search,$do_replace,$USER_TEMPLATE);
		//Set Headers
		$user_header = "Return-Path: ".$EMAIL_OPTIONS['TITLE']." <".$EMAIL_OPTIONS['FROM'].">\r\n"; 
		$user_header .= "From: ".$EMAIL_OPTIONS['TITLE']." <".$EMAIL_OPTIONS['FROM'].">\r\n";
		$user_header .= "Content-Type: ".$EMAIL_OPTIONS['TYPE']."; charset=".$EMAIL_OPTIONS['CHARSET'].";\n\n\r\n"; 
		//Send Thank you
		mail ($_POST['email'],$EMAIL_OPTIONS['USER_SUBJECT'],$user_message,$user_header);	
	}

	//Send admi email?
	if(count($ADMIN_EMAILS) > 0){
		$admin_message = str_replace($do_search,$do_replace,$ADMIN_TEMPLATE);
		//Do we need to send file as attachment?
		if($FILE_DO != 1){
			//Get file attriubtes
			$fileatt_type = $_FILES['user_file']['type'];

			$file = fopen($FILE_UPLOADS_DIR.$new_filename,'rb');
			while($dat = fread($file,1025657)){
				$attachment_data .= $dat;
			}
			fclose($file);

			// Encode file content
			$attachment_data = chunk_split(base64_encode($attachment_data));
			//File upload headers
			$semi_rand = md5(time());
			$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

			$headers = "From: ".$EMAIL_OPTIONS['TITLE']." <".$EMAIL_OPTIONS['FROM'].">";

			// Add the headers for a file attachment
			$headers .= "\nMIME-Version: 1.0\n" .
				"Content-Type: multipart/mixed;\n" .
				" boundary=\"{$mime_boundary}\"";						

			  // Add a multipart boundary above the plain message
			$new_message = "This is a multi-part message in MIME format.\n\n" .
				"--{$mime_boundary}\n" .
				"Content-Type: ".$EMAIL_OPTIONS['TYPE']."; charset=\"".$EMAIL_OPTIONS['CHARSET']."\"\n" .
				"Content-Transfer-Encoding: 7bit\n\n" .
				$admin_message . "\n\n";
		   			
			  // Add file attachment to the message
			 $new_message .= "--{$mime_boundary}\n" .
	             "Content-Type: {$fileatt_type};\n" .
	             " name=\"{$new_filename}\"\n" .
	             "Content-Disposition: attachment;\n" .
	             " filename=\"{$new_filename}\"\n" .
	             "Content-Transfer-Encoding: base64\n\n" .
	             $attachment_data . "\n\n" .
	             "--{$mime_boundary}--\n"; 

			unset($attachment_data);
		} else {
			//regular headers
			$headers = "Return-Path: ".$EMAIL_OPTIONS['TITLE']." <".$EMAIL_OPTIONS['FROM'].">\r\n"; 
			$headers .= "From: ".$EMAIL_OPTIONS['TITLE']." <".$EMAIL_OPTIONS['FROM'].">\r\n";
			$headers .= "Content-Type: ".$EMAIL_OPTIONS['TYPE']."; charset=".$EMAIL_OPTIONS['CHARSET'].";\n\n\r\n"; 
			$new_message = $admin_message;
		}
		//Send admin emails
		foreach($ADMIN_EMAILS as $this_email){
			mail ($this_email,$EMAIL_OPTIONS['USER_SUBJECT'],$new_message,$headers);	
		}
	}

	//Remove file if not needed
	if($FILE_DO == 2){
		unlink($FILE_UPLOADS_DIR.$new_filename);
	}
	$message = 'Your contact has been sent, thank you.';
	$_POST = NULL;
}
}
if($message != NULL){
?>
<center>
<table width="500"  border="0" cellpadding="5" cellspacing="0" bgcolor="#ffffff">
  <tr>
    <td bgcolor="#FFD5D5" align="center"><font color="#FF0000"><b><?=$message;?></b></font></td>
  </tr>
</table></center>
<br/>
<?php } ?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data" name="contact" id="contact" style="display:inline;">
<table width="620"  border="0" cellpadding="5" cellspacing="0" class="btext">
<tr>
  <td align="center" colspan="2">All fields with (<b>*</b>) must be completed.<br>
  If you are using anti-spam software, please allow emails from Poverello.org to be received.
</td>
</tr>
<tr>
  <td>First Name:</td>
	<td><input name="fname" type="text" id="fname" value="<?php echo $_POST['fname'];?>"> *</td>
</tr>
<tr>
  <td>Last Name:</td>
	<td><input name="lname" type="text" id="lname" value="<?php echo $_POST['lname'];?>"> *</td>
</tr>
<tr>
  <td>Businees or Orginaztion Name:</td>
	<td><input name="busname" type="text" id="busname" value="<?php echo $_POST['busname'];?>"> *</td>
</tr>
<tr>
  <td>Address:</td>
	<td><input maxlength="100" size="50" name="address1" type="text" id="address1" value="<?php echo $_POST['address1'];?>"> *</td>
</tr>
<tr>
  <td>Address:</td>
	<td><input maxlength="100" size="50" name="address2" type="text" id="address2" value="<?php echo $_POST['address2'];?>"></td>
</tr>
<tr>
  <td>City:</td>
	<td><input name="city" type="text" id="city" value="<?php echo $_POST['city'];?>"> *</td>
</tr>
<tr>
  <td>State:</td>
	<td><input maxlength="2" size="2" name="state" type="text" id="state" value="<?php echo $_POST['state'];?>"> *</td>
</tr>
<tr>
  <td>Zip Code:</td>
	<td><input maxlength="10" size="10"name="zip" type="text" id="zip" value="<?php echo $_POST['zip'];?>"> *</td>
</tr>
<tr>
  <td>Home Phone:</td>
	<td><input name="hphone" type="text" id="hphone" value="<?php echo $_POST['hphone'];?>"> *</td>
</tr>
<tr>
  <td>Business Phone:</td>
	<td><input name="wphone" type="text" id="wphone" value="<?php echo $_POST['wphone'];?>"> (optional)</td>
</tr>
	<tr>
  <td>Email:</td>
	<td><input name="email" type="text" id="email" value="<?php echo $_POST['email'];?>"> *</td>
</tr>
<tr>
  <td>Yor Web Page name:</td>
	<td><input name="webname" type="text" id="webname" value="<?php echo $_POST['webname'];?>"> *</td>
</tr>
<tr>
  <td>Target Fundraising &#40;&#36;&#41; Amount :</td>
	<td><input name="target" type="text" id="target" value="<?php echo $_POST['target'];?>"> *</td>
</tr>
<tr>	
  <td>Your Personal Message:</td>
	<td><textarea name="message_text" cols="40" rows="4" id="message_text"><?php echo $_POST['message_text'];?></textarea> *</td>
</tr>
<tr>	
  <td>Note to the Web Designer:</td>
	<td><textarea name="note_text" cols="40" rows="4" id="note_text"><?php echo $_POST['note_text'];?></textarea> *</td>
</tr>
<?php
if($IMAGE_VERIFICATION == 1){?>
<tr>
  <td>Verification code:</td>
	<td>		  <table border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td><?php
			$referenceid = md5(mktime()*rand());
			//Generate the random string
			$chars = array("a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J","k",
			"K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T","u","U","v",
			"V","w","W","x","X","y","Y","z","Z","1","2","3","4","5","6","7","8","9");
			$length = 8;
			$textstr = "";
			for ($i=0; $i<$length; $i++) {
			   $textstr .= $chars[rand(0, count($chars)-1)];
			}
			$new_string = RC4($textstr,$IMAGE_VER_CODE);
			$image_link = bin2hex($new_string);
			?>
			<img src="sec_image.php?code=<?=$image_link;?>">
			<input name="hid_code" type="hidden" id="hid_code" value="<?=$image_link;?>"><br/>
			<input name="confirm_image" type="text" id="confirm_image" value="<?php echo $_POST['confirm_image'];?>"></td>
		</tr>
		</table>
	</td>
</tr>
<?php }
if($FILE_UPLOAD == 1){?>
<tr>
  <td>Profile Image Upload </td>
      <td><table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td><input name="user_file" type="file" id="user_file">
              * </td>
        </tr>
        <tr>
          <td><font color="#FF0000" size="2">Max. File Size: 
            <?=$FILE_UPLOAD_MAX;?> 
            MB, Allowed Extensions: 
            <?php 
		if($FILE_UPLOADS_EXT == 1){ echo 'gif, jpg, jpeg, bmp';}else{
		foreach($FILE_UPLOADS_EXT as $ext){ echo '-'.$ext;}}?>
          </font></td>
        </tr>
      </table>        </td>
</tr>
<tr>
	<td colspan="2"><div align="center">
	<input type="submit" name="Submit" value="Send Contact">
	<input name="submit_id" type="hidden" id="submit_id" value="1">
	</div></td>
</tr>
<?php } ?>

</table>    
</form>
<?php

 

Mod edit: code tags added

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.