Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Arun Kumar on "Contact form with file upload problem"

$
0
0

Hi Friends..,

Here i paste my simple contact form code with form validation function... now i just add file uploading option in my form... but i don't know ... how to write the function for that option in this form.. Please guide me.... I am new for php.. Thank you to all

<?php
/*
Template Name: Contact
*/
?>
<?php
//If the form is submitted
if(isset($_POST['submit']))
 {
$subject = trim($_POST['subject']);
$comments = trim($_POST['message']);

	//Check to make sure that the name field is not empty
	if(trim($_POST['contactname']) == '') {
		$hasError = true;
	} else {
		$name = trim($_POST['contactname']);
	}

	//Check to make sure sure that a valid email address is submitted
	if(trim($_POST['email']) == '')  {
		$hasError = true;
	} else if (!preg_match("/^<a href="http://codex.wordpress.org/:alnum:">:alnum:</a>[a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
		$hasError = true;
	} else {
		$email = trim($_POST['email']);
	}

	//If there is no error, send the email
	if(!isset($hasError)) {
        $emailTo =  'arun@ariamindshare.com';//Put your own email address here
        $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:$comments";
        $headers = 'From: Neugen Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;  

        mail($emailTo, $subject, $body, $headers);
        $emailSent = true;
    }
}
?>
<?php get_header(); ?>

 <div id="banner">
 <div id="mast">
<ul class="images">

<li><img src="http://ariagreen.com/ng/wp-content/themes/twentyeleven-child/images/neugen_home_mast.jpg" alt="Aria MindShare1"></img></li>
</div>

<div class="headertext">

<pre>    YOUR GROWTH
    IS OUR PROMISE.</pre>
<pre class="p1" >      As discussed the whole idea of Neugen is to
      trade the products from manufacturers and
      be a commission agent or a facilitator. We
      have made tie-ups with many multiple
      companies from various backgrounds.
	  <a href=""> Read More</a></div>
</div>
<div id="center">
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<div id="contactform">
<p> Please enter your comments here </p>
<form method="post" action="<?php the_permalink(); ?>" id="form">
	<input type="text" name="contactname" value=""  placeholder="Name"  pattern="[-A-Z-a-z]+" required/>
	<input type="email" name="email" value="" placeholder="Email" required/>
	<input type="text" name="subject" value="" placeholder="Subject" />
        <input type="file" name="file" id="file" Value="" placeholder="File Upload"/></br>
	<textarea rows="8" name="message" placeholder="Message"></textarea>
	<input type="submit" value="Send" name="submit" id="button1" title="Click here" />

		<?php if(isset($hasError)) { //If errors are found ?>
			<p class="error">Please check if you've filled all the fields with valid information and try again. Thank you.</p>
		<?php } ?>

		<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
			<div class="success">
				<p></strong><strong>Email Successfully Sent!</strong></p>
			</div>
		<?php } ?>
		</form>
   </div>
<?php endwhile; ?>
<?php endif; ?>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>

Viewing all articles
Browse latest Browse all 8245

Trending Articles