Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: PHP Form Help

  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Form Help

    Hi there,

    Been having an issue with a form that I have been using from a tutorial, I want the form to validate (which it does perfectly at the minute, but on submit (if it is validated) I want it to redirect to another page...anyone any ideas?

    My code is
    [code]
    <div id="contact_form">
    <form method="post" action="assets/php/send.php" id="contactForm">
    <div class="error" id="error">An error occurer and the message can't be sent!</div>
    <div class="success" id="success">Email sent successfully!<br />Thank you for contacting us.</div>

    <span class="input">
    <label for="title"><b>Title:</b> </label>
    <input type="text" id="title" name="title" />
    <div class="warning" id="titleError">This field can't stay empty</div>
    </span>

    <span class="input">
    <label for="name"><b>Name:</b> </label>
    <input type="text" id="name" name="name" />
    <div class="warning" id="nameError">This field can't stay empty</div>
    </span>

    <span class="input">
    <label for="surname"><b>Surname:</b> </label>
    <input type="text" id="surname" name="surname" />
    <div class="warning" id="surnameError">This field can't stay empty</div>
    </span>

    <span class="input">
    <label for="email"><b>Email:</b> </label>
    <input type="text" id="email" name="email" />
    <div class="warning" id="emailError">Enter with a valid email!</div>
    </span>

    <span class="input">
    <label for="phone"><b>Phone:</b> </label>
    <input type="text" id="phone" name="phone" />
    <div class="warning" id="phoneError">Only digits are accepted!</div>
    </span>

    <span class="input">
    <label for="sales"><b>Sales:</b> </label>
    <select id="sales" name="sales">
    <option value="Support">Support</option>
    <option value="Sales">Sales</option>
    <option value="Other">Other</option>
    </select>
    </span>

    <span class="input">
    <label for="message"><b>Message:</b> </label>
    <textarea id="message" name="message">Hello,
    </textarea>
    <div class="warning" id="messageError">This field can't stay empty</div>
    </span>

    <span class="input">
    <label for="security_code"><b>Security Code:</b> </label>
    <input class="noicon" type="text" id="security_code" name="security_code" style="width:100px" />
    <img src="assets/php/security/1/sec.php" style="vertical-align:middle;" />
    <div class="warning" id="security_codeError">The security code is wrong!</div>
    </span>
    <span id="submit" class="input">
    <label for="submit"></label>
    <p id="ajax_loader" style="text-align:center;"><img src="assets/img/contact/ajax-loader.gif" /></p>
    <input id="send" type="submit" value="SEND" />
    </span>

    </form>

    [code]

    I am guessing I need to chnage the code withing the first few lines I am just not sure what too.

    Thanks.
    Lee

  • #2
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    339
    Thanks
    63
    Thanked 11 Times in 11 Posts
    This is just the HTML, you need to show us the PHP.

    In your 'send.php' you need to write an IF statement whereby the user will be forwarded if the validation is passed.

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    The redirect will happen on the script that processes the form.

    Right now, the method used looks like AJAX, where it makes the "success"
    <div> visible if validation is correct, but that appears on the same page
    as the form.

    To redirect would involve modifying the script that "unhides, or makes visible"
    the <div class>. Not sure whether that happens in a .js script? But you'll need
    to make several modifications to make it work.

  • #4
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So my send.php has the following in it:

    [code]
    <?php
    //www.resellscripts.info
    error_reporting(E_ALL);
    if(getenv('REQUEST_METHOD') != 'POST')
    exit('Opss! Only POST requests are accepted');

    include_once 'config.class.php';
    include_once 'protector.class.php';
    include_once 'email.class.php';

    define('DS' , DIRECTORY_SEPARATOR);

    $email = new Email($_POST);
    $email->init();

    ?>
    [code]

    where would i need to create the IF statement?

  • #5
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    339
    Thanks
    63
    Thanked 11 Times in 11 Posts
    Ok, there's more going on with this than I thought. It's the problem with pulling a tutorial script and trying to modify it.

  • #6
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ahh ok, im not great with php but unfortuantely it is a must. Thanks for your help anyway

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Lee ...
    Give us the source where you found the tutorial (or example scripts).


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •