Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

question about my for,

  • 09-07-2012 09:39AM
    #1
    Registered Users, Registered Users 2 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,144 ✭✭✭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, Registered Users 2 Posts: 287 ✭✭Keewee6


    thanks for the help and advice much appreciated


  • Registered Users, Registered Users 2 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