Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

question about my for,

Options
  • 09-07-2012 10:39am
    #1
    Registered Users Posts: 287 ✭✭


    <?php
    if (isset($_REQUEST))

    //if "email" is filled out, send email
    {
    //send email
    $name = $_REQUEST ;
    $email = $_REQUEST ;
    $subject = $_REQUEST ;
    $message = $_REQUEST ;
    mail("info@bailieborough.com", "$subject",
    $message, "From:" . $email);
    echo "Thank you for using our mail form";
    }
    else
    //if "email" is not filled out, display the form
    {
    echo "<form method='post' action='contactus.php'>
    Name:<br /> <input name='name' type='text' /><br />
    Email: <br /><input name='email' type='text' /><br />
    Subject:<br /> <input name='subject' type='text' /><br />
    Message:<br />
    <textarea name='message' rows='15' cols='40'>
    </textarea><br />
    <input type='submit' />
    </form>";

    }
    ?>

    i was wondering is there a way to force a user to fill in all fields or the form wont send thanks in advance


Comments

  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    First of all, some light reading: http://www.securephpwiki.com/index.php/Email_Injection
    The gist of it is that people can abuse that form to send what ever email they want to who ever they want. Which is a good way to get spam blacklisted.
    It would be better to use a third-party script/class/library, where these injection problems are already taken care of.

    Anyway, you could make sure a form field wasn't left blank by doing something like:
    [php]
    if(strlen($_REQUEST ) < 1)
    {
    die('Subject cannot be empty');
    }
    [/php]
    Obviously you'd want to do something more graceful than die(), but strlen() should do it.


  • Registered Users Posts: 287 ✭✭Keewee6


    thanks for the help and advice much appreciated


  • Registered Users Posts: 43 allaboutclicks


    You could also use the isset() function for the inputs as well as the form. For example
    if (!isset($_REQUEST)) {//populate error array}
    then use an if statement that the form only submits if error array is empty and you can also use the error array to list errors on the form.


Advertisement