contactus.php help needed

Discussion in 'PHP' started by ghazal, Nov 23, 2009.

  1. #1
    I think its very simple but I am confused in coding this script.

    I want a contactus.php page where users enter/input their DATA, and when they hit submit button, the data will sent to my email and if those users enter a value of YES will redirect to thankyou.htm page and if they enter NO then their data submit to my email and they didn't redirect to thankyou.htm page.

    The page contains the folowing values;

    Name: [Text Box]
    Father's Name: [Text Box]
    Age: [Text Box]
    Sex: [MALE/ FEMALE Options]
    Address: [Text area option]
    Marital Status: [Single/Married/Divorced options]
    Another Option: [Yes/No options] <--- Here if user select Yes then after submitting the form, he should redirect to thankyou.htm otherwise no redirect.

    It will really appreciated if you enter a Capatcha varification for the page.

    Thankyou very much for guiding me.

    Best regards
     
    ghazal, Nov 23, 2009 IP
  2. shubhamjain

    shubhamjain Active Member

    Messages:
    215
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    63
    #2
    I have one Captcha script. But why to do it complex way anyway.

    Just do some click and make a form on JotForm - http://www.jotform.com/.
     
    shubhamjain, Nov 23, 2009 IP
  3. ghazal

    ghazal Member

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #3
    Thanks for the link: but I want my own script rather to use any other's server for collecting the information and submitting to my email.
     
    ghazal, Nov 24, 2009 IP
  4. shubhamjain

    shubhamjain Active Member

    Messages:
    215
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    63
    #4
    Ok. I guess you only require captcha script?
     
    shubhamjain, Nov 24, 2009 IP
  5. ghazal

    ghazal Member

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #5
    Not only Captcha, but a complete contactus form script. If you provide me I will be very thankful to you :)
     
    ghazal, Nov 24, 2009 IP
  6. uworks

    uworks Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Make google your friend ;)
    Just google this contact us script with captcha.
    If you need more help check this link http://www.thewebhelp.com/php/php_contact_form_with_image_validation
    If you need any further assistance just PM me.
     
    uworks, Nov 24, 2009 IP
  7. peter_anderson

    peter_anderson Notable Member

    Messages:
    3,382
    Likes Received:
    152
    Best Answers:
    0
    Trophy Points:
    240
    #7
    Use an if statement.

    <select name="select"><option value="yes">Yes</option><option value="no">No</option></select>
    Code (markup):
    And, for the contactform page:

    if($_POST['select'] == 'yes'){
    //redirect
    //mail(
    }else{
    //something else
    }
    Code (php):
    Hope that gelps
     
    peter_anderson, Nov 24, 2009 IP
  8. ghazal

    ghazal Member

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #8
    Thanks Peter Anderson, Can you make me a complete contactus.php page ? All values are in the OP. Thankyou for help.

    Please use this email for submitting the data:
    Please use this page for redirection: thankyou.htm
     
    ghazal, Nov 24, 2009 IP
  9. peter_anderson

    peter_anderson Notable Member

    Messages:
    3,382
    Likes Received:
    152
    Best Answers:
    0
    Trophy Points:
    240
    #9
    I don't normally do free code, but since it's easy, here you go.

    form.php
    <?php
    
    # you can add your header here
    
    # our functions
    function check_input($data, $problem='')
    {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        if ($problem && strlen($data) == 0)
        {
            show_error($problem);
        }
        return $data;
    }
    
    function show_error($myError)
    {
    $content = '<h2>
    	Error processing your form.</h2>
    <p>
    	We are sorry, but we experienced an error while submitting your form.</p>
    <p>
    	Error:<br />
    	'.$myError.'</p>';
    }
    
    switch($_GET['action']){
    case "thanks":
    $content = '<h2>
    	Form processed!</h2>
    <p>
    	Your forum submission has been processed by our online form processing service.</p>
    <p>
    	&nbsp;</p>
    <p>
    	Thanks!</p>
    <p>
    	<a href="http://www.regyourdomain.com">For domain names, visit RegYourDomain.</a></p>';
    break;
    case "confirm":
    $myemail = 'me@me.com'; //write your email address between the ' '
    
    $uname  = check_input($_POST['name'], "Specify your full name");
    $dad  = check_input($_POST['dad'], "Let us know your fathers name");
    $age  = check_input($_POST['age'], "What age are you?");
    $address = check_input($_POST['address'], "Please input your address");
    $marry = check_input($_POST['marry'], "Specify your marital status.");
    $option  = check_input($_POST['option']);
    
    $message = "A new form has been submitted from your website.
    
    Name: $uname
    Fathers name: $dad
    Age: $age
    Address: $address
    Marital Option: $option
    
    Thanks.";
    
    if($_POST['select'] == 'No'){
    $subject = 'A new form has been processed';
    mail($myemail, $subject, $message);
    $content = '<h2>
    	Thanks!</h2>
    <p>
    	Thanks for submitting your form.</p>
    <p>
    	Redirecting.....</p>
    <meta http-equiv="refresh" content="0;url=?action=thanks" />';
    mail($myemail, $subject, $message);
    }else{
    $content = '<meta http-equiv="refresh" content="0;url=?action=thanks" />';
    }
    
    break;
    default:
    $content = '<h2>
    	Submit your details</h2>
    <form action="form.php?action=submit" method="post" name="submit">
    	<table border="1" cellpadding="1" cellspacing="1" style="width: 100%">
    		<tbody>
    			<tr>
    				<td>
    					Name:</td>
    				<td>
    					<input name="name" type="text" /></td>
    			</tr>
    			<tr>
    				<td>
    					Father\'s Name:</td>
    				<td>
    					<input name="dad" type="text" /></td>
    			</tr>
    			<tr>
    				<td>
    					Age:</td>
    				<td>
    					<input name="age" type="text" /></td>
    			</tr>
    			<tr>
    				<td>
    					Sex:</td>
    				<td>
    					<select name="sex"><option selected="selected" value="M">Male</option><option value="F">Female</option></select></td>
    			</tr>
    			<tr>
    				<td>
    					Address:</td>
    				<td>
    					<textarea cols="40" name="address"></textarea></td>
    			</tr>
    			<tr>
    				<td>
    					Marital Status:</td>
    				<td>
    					<select name="marry"><option selected="selected" value="Married">Married</option><option value="Single">Single</option><option value="Engaged">Engaged</option><option value="Divorced">Divorced</option><option value="With partner">With partner</option></select></td>
    			</tr>
    			<tr>
    				<td>
    					Option:</td>
    				<td>
    					<select name="option"><option selected="selected" value="Yes">Yes</option><option value="No">No</option></select></td>
    			</tr>
    			<tr>
    				<td>
    					&nbsp;</td>
    				<td>
    					<input name="submit" type="button" value="Submit my Form!" /></td>
    			</tr>
    		</tbody>
    	</table>
    </form>';
    break;
    }
    
    echo $content;
    
    # you can add your footer here
    
    ?>
    
    Code (php):
    There isn't any captcha, but you can add it yourself.
     
    peter_anderson, Nov 24, 2009 IP
  10. ghazal

    ghazal Member

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #10
    Thankyou Peter Anderson
     
    ghazal, Nov 24, 2009 IP