Jump to content

Choreographing my PHP file with my Echo


Taylor84

Recommended Posts

File should be a .php extension unless server is configured to parse php in html.

For each $_GET['key'] you would check for...it must be looking for the same name in the form.

 

I did a new form that should work for you, in this example I did an all together 10 digits for phone numbers.

Here is a post for other telephone checking patterns.

http://forums.phpfreaks.com/topic/296613-validation-issue/?do=findComment&comment=1513077

 

Redirects back to main site after 5 seconds with a message, only because you are including a header, otherwise would have displayed the message back into the form.

 

Optional google recaptcha included, just insert key first line if have one.

 

Can try this out and let me know.

<?php
$recaptcha_key = "";//optional google recaptcha

if (isset($_POST['submit'])) {
    $errors = array();
    $msg = "";//keep empty
    
    if (isset($_POST['fname']) && trim($_POST['fname']) != '') {
        $fname = trim($_POST['fname']);
    } else {
        $fname     = '';
        $errors[] = 'first name';
    }
    
    if (isset($_POST['lname']) && trim($_POST['lname']) != '') {
        $lname = trim($_POST['lname']);
    } else {
        $lname     = '';
        $errors[] = 'last name';
    }
    
    if (isset($_POST['company']) && trim($_POST['company']) != '') {
        $company = trim($_POST['company']);
    } else {
        $company  = '';
        $errors[] = 'company';
    }
    
    if (isset($_POST['email']) && filter_var(trim($_POST['email']), FILTER_VALIDATE_EMAIL)) {
        $email = trim($_POST['email']);
    } else {
        $email    = '';
        $errors[] = 'email';
    }
    
    if (isset($_POST['phone']) && ctype_digit($_POST['phone']) && strlen($_POST['phone']) == 10) {
        $phone = trim($_POST['phone']);
    } else {
        $phone  = '';
        $errors[] = 'phone';
    }
    
    if (isset($_POST['message']) && trim($_POST['message']) != '') {
        $message = trim($_POST['message']);
    } else {
        $message  = '';
        $errors[] = 'message';
    }
    
if(!empty($recaptcha_key)){
    if(isset($_POST['g-recaptcha-response'])){
        $captcha=$_POST['g-recaptcha-response'];
    }    
    
    if(!$captcha){
          $errors[] = 'captcha';
    } else {
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_key."&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
        if($response.success==false){
          $errors[] = 'captcha';
        }
    }
}
    
    if (empty($errors)) {
        //escape,filter,sanitize data and insert data to mysql
        echo "<p style='color:#66FF00;'>Thank you, we will contact you within 24 hours.</p>";
        header("refresh:5; url=http://".$_SERVER['SERVER_NAME']);
        exit;
    } else {
        $msg = "<p style='color:#FF3300;'>You have the following errors:" . implode($errors, ", ") . "</p>";
    }
}
?>


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ARSI | AUTOMATED RESCORE SYSTEMS</title>
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<?php
include "include/head.php";

if(!empty($recaptcha_key)){
?>
<script src='https://www.google.com/recaptcha/api.js'></script>
<?php }?>
<style>
*:focus {
    outline: none;
}
body {
    font: 14px/21px "Lucida Sans", "Lucida Grande", "Lucida Sans Unicode", sans-serif;
    max-width:99%;
}
a {
    text-decoration:none;
}
.wrap{
    position:relative;
    width:75%;
    margin-left:auto;
    margin-right:auto;
    padding:5px;
}
ul{
    list-style-type: none;
    padding:0;
    margin:0;
}
.contact_form h2, .contact_form label {
    font-family:Georgia, Times, "Times New Roman", serif;
}
.form_hint, .required_notification {
    font-size: 11px;
}
.contact_form ul {
    width:750px;
    list-style-type:none;
    list-style-position:outside;
    margin:0px;
    padding:0px;
}
.contact_form li{
    padding:12px;
    border-bottom:1px solid #eee;
    position:relative;
}
.contact_form li:first-child, .contact_form li:last-child {
    border-bottom:1px solid #777;
}
.contact_form h2 {
    margin:0;
    display: inline;
}
.required_notification {
    color:#d45252;
    margin:5px 0 0 0;
    display:inline;
    float:right;
}
.contact_form label {
    width:150px;
    margin-top: 3px;
    display:inline-block;
    float:left;
    padding:3px;
}
.contact_form input {
    height:20px;
    width:300px;
    padding:5px 8px;
    -moz-transition: padding .25s;
    -webkit-transition: padding .25s;
    -o-transition: padding .25s;
    transition: padding .25s;
}
.contact_form textarea {
    padding:8px;
    width:300px;
    -moz-transition: padding .25s;
    -webkit-transition: padding .25s;
    -o-transition: padding .25s;
    transition: padding .25s;
}
.contact_form button {
    margin-left:156px;
}
.contact_form input, .contact_form textarea {
    padding-right:30px;
    border:1px solid #aaa;
    box-shadow: 0px 0px 3px #ccc, 0 10px 15px #eee inset;
    border-radius:2px;
}
.contact_form input:focus, .contact_form textarea:focus {
    background: #fff;
    border:1px solid #555;
    box-shadow: 0 0 3px #00FF00;
    padding-right:70px;
}
/* Button Style */
button.submit {
    background-color: #68b12f;
    background: -webkit-gradient(linear, left top, left bottom, from(#68b12f), to(#50911e));
    background: -webkit-linear-gradient(top, #68b12f, #50911e);
    background: -moz-linear-gradient(top, #68b12f, #50911e);
    background: -ms-linear-gradient(top, #68b12f, #50911e);
    background: -o-linear-gradient(top, #68b12f, #50911e);
    background: linear-gradient(top, #68b12f, #50911e);
    border: 1px solid #509111;
    border-bottom: 1px solid #5b992b;
    border-radius: 3px;
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    -ms-border-radius: 3px;
    -o-border-radius: 3px;
    box-shadow: inset 0 1px 0 0 #9fd574;
    -webkit-box-shadow: 0 1px 0 0 #9fd574 inset ;
    -moz-box-shadow: 0 1px 0 0 #9fd574 inset;
    -ms-box-shadow: 0 1px 0 0 #9fd574 inset;
    -o-box-shadow: 0 1px 0 0 #9fd574 inset;
    color: white;
    font-weight: bold;
    padding: 6px 20px;
    text-align: center;
    text-shadow: 0 -1px 0 #396715;
}
button.submit:hover {
    opacity:.85;
    cursor: pointer;
}
button.submit:active {
    border: 1px solid #20911e;
    box-shadow: 0 0 10px 5px #356b0b inset;
    -webkit-box-shadow:0 0 10px 5px #356b0b inset ;
    -moz-box-shadow: 0 0 10px 5px #356b0b inset;
    -ms-box-shadow: 0 0 10px 5px #356b0b inset;
    -o-box-shadow: 0 0 10px 5px #356b0b inset;
    
}
input:required, textarea:required {
    background: #fff;
    border-color:#FF0000;
    
}
.contact_form input:required:valid, .contact_form textarea:required:valid { /* when a field is considered valid by the browser */
    background: #fff;
    box-shadow: 0 0 5px #5cd053;
    border-color: #28921f;
}
.form_hint {
    background: #d45252;
    border-radius: 3px 3px 3px 3px;
    color: white;
    margin-left:8px;
    padding: 1px 6px;
    z-index: 999; /* hints stay above all other elements */
    position: absolute; /* allows proper formatting if hint is two lines */
    display: none;
}
.form_hint::before {
    content: "\25C0"; /* left point triangle in escaped unicode */
    color:#d45252;
    position: absolute;
    top:1px;
    left:-6px;
}
.contact_form input:focus + .form_hint {
    display: inline;
}
.contact_form input:required:valid + .form_hint {
    background: #28921f;
}
.contact_form input:required:valid + .form_hint::before {
    color:#28921f;
}

</style>
</head>
<body>
<div class="wrap">
<form class="contact_form" action="" method="post" name="contact_form" novalidate>
<ul>
<li>
    <h2>PARTNERS</h2>
    <button style="float:right;"><a href="partner-login.php">PARTNER LOGIN</a></button>
    <p>Are you interested in becoming a Partner?<br/>Please fill out the form below and we will contact you within 24 hours.</p>
</li>    
<?php echo $msg;?>
<li>
<label for="fname">First Name:</label>
<input id="fname" name="fname" type="text" value="<?php echo $fname;?>" required/>
</li>
<li>
<label for="lname">Last Name:</label>
<input id="lname" name="lname" type="text" value="<?php echo $lname;?>" required/>
</li>
<li>
    <label for="company">Company:</label>
    <input id="company" name="company" type="text" value="<?php echo $company;?>" required/>
</li>
<li>
    <label for="email">Email:</label>
    <input id="email" name="email" type="email" value="<?php echo $email;?>" required/>
    <span class="form_hint">Format "name@domain.com"</span>
</li>
<li>
    <label for="phone">Phone Number:</label>
    <input id="phone" name="phone" type="tel" pattern="\d{10}" title='Phone Number (Format: 0123456789 10 digits)' value="<?php echo $phone;?>" required/>
    <span class="form_hint">Format "0123456789 10 digits"</span>   
</li>
<li>
    <label for="message">Message:</label>
    <textarea id="message" name="message" cols="40" rows="4" required><?php echo $message;?></textarea>
</li>
<?php
if(!empty($recaptcha_key)){
?>
<div class="g-recaptcha" data-sitekey="$recaptcha_key"></div>

<?php }?>
<li>
    <button class="submit" type="submit" name="submit">Submit Form</button>
</li>
</ul>
</form>

<div>
<?php include "include/footer.php";?>
</body>
</html>
Edited by QuickOldCar
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.