325252525252 Posted June 27, 2013 Share Posted June 27, 2013 Hello fellow Commanders i have a question i'm crap with php but made this request form and i have a question why the hell it still would let to send empty messages? im trying to avoid flood so I added request but even if request form completely blank it still succeeds ;( can someone explain me please thank you so much btw form itself is in html website <?php if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email']; $phone = $_REQUEST['phone']; $message = $_REQUEST['message']; $name = $_REQUEST['name']; $headers = "\r Name: $name \r\n"; $headers .= "Email: $email \r\n"; $headers .= "Telephone: $phone \r\n"; $headers .= "Message: $message \r\n"; $today = date("j, n, Y"); mail( 'xxx@gmail.com', "Request from xxxx.co.uk", 'IP: '.$_SERVER['REMOTE_ADDR'] .$headers. 'Date: '.$today); header('Refresh: 0; URL=http://xxxx.co.uk/contacts/success.htm'); } else //if "email" is not filled out, print error { print( 'error fuck off'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/279638-simple-request-form-script/ Share on other sites More sharing options...
325252525252 Posted June 27, 2013 Author Share Posted June 27, 2013 i will formalise my question: how can i stop empty emails? thanks Quote Link to comment https://forums.phpfreaks.com/topic/279638-simple-request-form-script/#findComment-1438236 Share on other sites More sharing options...
AbraCadaver Posted June 27, 2013 Share Posted June 27, 2013 $_REQUEST['email'] will be set even if it is empty. Try: if (!empty($_REQUEST['email'])) Quote Link to comment https://forums.phpfreaks.com/topic/279638-simple-request-form-script/#findComment-1438248 Share on other sites More sharing options...
ginerjm Posted June 27, 2013 Share Posted June 27, 2013 check if email is empty before processing? if ($email == '') { echo "you didn't provide a message"; echo "<br><a href='" . $_SERVER['PHP_SELF'] . "'>Try Again</a>"; exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/279638-simple-request-form-script/#findComment-1438252 Share on other sites More sharing options...
325252525252 Posted June 27, 2013 Author Share Posted June 27, 2013 $_REQUEST['email'] will be set even if it is empty. Try: if (!empty($_REQUEST['email'])) great job thank you so muuch finally works! Quote Link to comment https://forums.phpfreaks.com/topic/279638-simple-request-form-script/#findComment-1438259 Share on other sites More sharing options...
325252525252 Posted June 27, 2013 Author Share Posted June 27, 2013 (edited) so that's what we have so far and it works perfect! but it will only requires for message how can i add email name and phone to be required as well? i tried all my known ways didn't work <?phpif (!empty($_REQUEST['message'])) { $email = $_REQUEST['email']; $phone = $_REQUEST['phone']; $message = $_REQUEST['message']; $name = $_REQUEST['name']; $headers = "\r Name: $name \r\n"; $headers .= "Email: $email \r\n"; $headers .= "Telephone: $phone \r\n"; $headers .= "Message: $message \r\n"; $today = date("j, n, Y"); mail( 'roxxx@gmail.com', "Request from axxxl.co.uk", 'IP: '.$_SERVER['REMOTE_ADDR'] .$headers. 'Date: '.$today); header('Refresh: 0; URL=http://xxx.uk/contacts/success.htm'); } else { header("HTTP/1.1 404 Not Found"); die('Please fill in all required fields.'); }?> Edited June 27, 2013 by 325252525252 Quote Link to comment https://forums.phpfreaks.com/topic/279638-simple-request-form-script/#findComment-1438264 Share on other sites More sharing options...
AbraCadaver Posted June 27, 2013 Share Posted June 27, 2013 Lots of ways. It would be best to do additional checking to make sure email is valid, phone is valid etc. But heres a quick easy one: if(count(array_filter($_REQUEST)) == count($_REQUEST)) { Quote Link to comment https://forums.phpfreaks.com/topic/279638-simple-request-form-script/#findComment-1438268 Share on other sites More sharing options...
325252525252 Posted June 27, 2013 Author Share Posted June 27, 2013 Lots of ways. It would be best to do additional checking to make sure email is valid, phone is valid etc. But heres a quick easy one: if(count(array_filter($_REQUEST)) == count($_REQUEST)) { beautiful thanks Quote Link to comment https://forums.phpfreaks.com/topic/279638-simple-request-form-script/#findComment-1438271 Share on other sites More sharing options...
325252525252 Posted June 27, 2013 Author Share Posted June 27, 2013 (edited) one last thing I added this anti-flood thing 'enter 4 digits code' but I can't come up with the php script for it could you help? shouldn't be hard for you. I tried something like this but didn't work lol btw 7D6Z is the only code image i have so its not random. its 7D6Z everytime lol if (!empty($_REQUEST['password'])) http://imageshack.us/photo/my-images/853/cnso.jpg/ Edited June 27, 2013 by 325252525252 Quote Link to comment https://forums.phpfreaks.com/topic/279638-simple-request-form-script/#findComment-1438300 Share on other sites More sharing options...
AbraCadaver Posted June 27, 2013 Share Posted June 27, 2013 I don't know what you called your 4 digit code, but assuming its 'code' then try this: if(count(array_filter($_REQUEST)) == count($_REQUEST) && strtoupper($_REQUEST['code']) == '7D6Z') { Quote Link to comment https://forums.phpfreaks.com/topic/279638-simple-request-form-script/#findComment-1438302 Share on other sites More sharing options...
325252525252 Posted June 27, 2013 Author Share Posted June 27, 2013 (edited) pointless post Edited June 27, 2013 by 325252525252 Quote Link to comment https://forums.phpfreaks.com/topic/279638-simple-request-form-script/#findComment-1438303 Share on other sites More sharing options...
325252525252 Posted June 27, 2013 Author Share Posted June 27, 2013 (edited) I don't know what you called your 4 digit code, but assuming its 'code' then try this:if(count(array_filter($_REQUEST)) == count($_REQUEST) && strtoupper($_REQUEST['code']) == '7D6Z') { guess what it works dam you good. Edited June 27, 2013 by 325252525252 Quote Link to comment https://forums.phpfreaks.com/topic/279638-simple-request-form-script/#findComment-1438306 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.