Jump to content

Need Help in PHP Form


tezzo

Recommended Posts

  


  <?php


    if(isset($_POST['txtEmail'])) {




    // EDIT THE 2 LINES BELOW AS REQUIRED


    $email_to = "xyz@abc.com"; 
    $email_subject = "Subject"; 
    $email_from = "abc@xyz.com";


    function died($error) {


    // your error code can go here


    echo "We are very sorry, but there were error(s) found with the form you submitted. ";


    echo "These errors appear below.";


    echo $error."<br /><br />";


    echo "Please go back and fix these errors.<br /><br />";


    die();


    }


    // validation expected data exists


    if(!isset($_POST['txtName']) ||
    !isset($_POST['txtEmail']) ||
    !isset($_POST['txtAddress']) ||
    !isset($_POST['txtContact']) ||  
    !isset($_POST['txtUpload'])) { 
    died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }






    $name = $_POST['txtName']; // required 
    $email = $_POST['txtEmail']; // required 
    $address = $_POST['txtAddress']; // required
    $contact = $_POST['txtContact']; // not required 
    $upload = $_POST['txtUpload']; // required


    $email_message = "Form Details are below.\n\n";






    function clean_string($string) {


    $bad = array("content-type","bcc:","to:","cc:","href");


    return str_replace($bad,"",$string);


    }






    $email_message .= "Full Name: ".clean_string($name)."\n\n";  
    $email_message .= "Address: ".clean_string($address)."\n\n";
    $email_message .= "Email ID: ".clean_string($email)."\n\n"; 
    $email_message .= "Contact No.: ".clean_string($contact)."\n\n";    
    $email_message .= "File: ".clean_string($upload)."\n\n";




    // create email headers


    $headers = 'From: '.$email_from."\r\n".


    'Reply-To: '.$email."\r\n" .


    'X-Mailer: PHP/' . phpversion();


    @mail($email_to, $email_subject, $email_message, $headers);  


    ?>






    <!-- include your own success html here -->






    Thank you for contacting us. We will be in touch with you very soon.






    <?php




    }


    ?>

 

 

i am a rookie in php

 

 

I got 2 problems

 

1) I am not able to insert a code for file upload in the above code.

 

2) In other type of form (with different textfields).i have a text (it is like a disclaimer) in the html form which i want it in email too.

Edited by Zane
Link to comment
Share on other sites

 

 

1) I am not able to insert a code for file upload in the above code.

See Handling file uploads in the PHP manual

 

 

 

2) In other type of form (with different textfields).i have a text (it is like a disclaimer) in the html form which i want it in email too.

Copy the disclaimer text and assign it to a variable, and then concatenate that onto $email_message

$diclaimerText = 'your disclaimer';
...
$email_message .= "--------------------------------\n\n$disclaimerText"; // append disclaimer to email
Link to comment
Share on other sites

i am unable to understand where to insert the code...in php i only know how to replace the existing textfield names with my textfields name and email id...so you can imagine my knowledge in php.......would you please show to where do i add the code.....Sorry for troubles

Link to comment
Share on other sites

well....Client wants the disclaimer also in the email....i dont want at the end of it........it is the middle.....but this is not the script fot that......i just have to edit the textfield name....i dont know what code should i put in my script

Link to comment
Share on other sites

 

 

.Client wants the disclaimer also in the email....i dont want at the end of it........it is the middle

This code here sets the text for the body of the email

$email_message .= "Full Name: ".clean_string($name)."\n\n";  
$email_message .= "Address: ".clean_string($address)."\n\n";
$email_message .= "Email ID: ".clean_string($email)."\n\n"; 
$email_message .= "Contact No.: ".clean_string($contact)."\n\n";    
$email_message .= "File: ".clean_string($upload)."\n\n";

Place 

$email_message .= "your email disclaimer text\n\n";

Where the client wants the disclaimer to appear. So if it is after the  Address, then add the line of code above after the Address line.

 

 

 

.but this is not the script fot that......i just have to edit the textfield name....i dont know what code should i put in my script

What? I do not understand.

Link to comment
Share on other sites

  • 3 weeks later...

i want to insert validations for radio buttons in the above form........(I tried many scripts but no luck)

 

below is my html code

<form>

     <input type="radio" name="txtRadio" value="Purchase"> Purchase
     <input type="radio" name="txtRadio" value="Sell"> Sell

</form>

Link to comment
Share on other sites

You just need to check to see what value $_POST['txtRadio'] holds when the form is submitted

if(isset($_POST['txtRadio']))
{
    if($_POST['txtRadio'] == 'Purchase')
    {
       // the Purchase radio button was selected
    }
    elseif($_POST['txtRadio'] == 'Sell')
    {
        // the Sell radio button was selected
    }
    else
    {
       // the user submitted an unexpected value?
    }
}
else
{
    // the user did not select a radio button
}
Edited by Ch0cu3r
Link to comment
Share on other sites

  • 1 month later...

can u tell me how can i add BCC in the above script......i tried a few ways...like

 

1) $headers .= "\r\nBcc: her@$herdomain\r\n\r\n";

 

 

2) $email_bcc = "xyz@abc.com"; (top half after $email_to and then adding it at the bottom half 'Bcc: '$email_bcc."\r\n" . after  'Reply-To: '.$email."\r\n" .)

 

I am getting syntax error for 2nd method.

Not able to understand whats wrong

Link to comment
Share on other sites

  • 4 weeks later...

hey...thank you so much for your reply...you are a genius.....(Sorry for late comment)...

 

I am stuck again....

 

on submitting the form......i want to show the error and successful message on the same page.....by hiding the contact form.....

 

 

e.g Feedback form on the homepage of http://www.flipkart.com/

 

(Don't worry about the animation)

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.