oavs Posted December 7, 2009 Share Posted December 7, 2009 Hi , Can anyone please help me with this simple script. This is a flash site calls for a external php contact.php file to submit flash form. It is all working. The only thing I want to do is when the fields are empty, I like form to NOT submit. I have been getting a lot of empty emails without content. Here is the code, let me know if anything else you need to know. Also is it possible to submit the IP of the user. This is not important but if it can be done without the flash file would be great. Many thanks <?php $sendto = 'xyz@domain.com.au'; $subject = 'Message From XXXYYYZZZ'; $name = $_POST['fromname']; $from = $_POST['fromemail']; $phone = $_POST['fromphone']; $message = $_POST['frommessage']; $message = stripslashes($message); $content = "Name: " . $ip . "\n"; $content = "Name: " . $name . "\n"; $content .= "Email: " . $from . "\n\n"; $content .= "Phone: " . $phone . "\n\n"; $content .= $message; //if(mail($sendto,$subject,$content)) if(empty($content )) { echo 'response=failed'; } elseif(mail($sendto,$subject,$content)) { echo 'response=passed'; } ?> <?php //original code //$sendto = 'xyz@domain.com.au'; //$subject = 'Message From XXXYYYZZZ'; //$name = $_POST['fromname']; //$from = $_POST['fromemail']; //$phone = $_POST['fromphone']; //$message = $_POST['frommessage']; //$message = stripslashes($message); //$content = "Name: " . $name . "\n"; //$content .= "Email: " . $from . "\n\n"; //$content .= "Phone: " . $phone . "\n\n"; //$content .= $message; //if(mail($sendto,$subject,$content)) //{ // echo 'response=passed'; //} //else //{ // echo 'response=failed'; //} ?> Quote Link to comment https://forums.phpfreaks.com/topic/184226-please-help-with-form-field-when-empty-not-to-submit/ Share on other sites More sharing options...
oavs Posted December 7, 2009 Author Share Posted December 7, 2009 If this helps, here is the flash code: send_btn.addEventListener(MouseEvent.CLICK, submit); function submit(e:MouseEvent):void { var variables:URLVariables = new URLVariables(); variables.fromname = Name_txt.text; variables.fromemail = Email_txt.text; variables.fromephone = Phone_txt.text; variables.frommessage = Message_txt.text; var req:URLRequest = new URLRequest("contact.php"); req.data = variables; req.method = URLRequestMethod.POST; var loader:URLLoader = new URLLoader(); loader.dataFormat = URLLoaderDataFormat.VARIABLES; loader.addEventListener(Event.COMPLETE, Success); loader.addEventListener(IOErrorEvent.IO_ERROR, Failed); loader.load(req); Status_txt.text = "Sending..."; } function Success(e:Event):void { Status_txt.text = "Success! The message was sent!"; Name_txt.text = ""; Email_txt.text = ""; Phone_txt.text = ""; Message_txt.text = ""; } function Failed(e:IOErrorEvent):void { Status_txt.text = "There was an error. Please try again later."; } Quote Link to comment https://forums.phpfreaks.com/topic/184226-please-help-with-form-field-when-empty-not-to-submit/#findComment-972622 Share on other sites More sharing options...
rajivgonsalves Posted December 7, 2009 Share Posted December 7, 2009 your code should be as follows also I feel you should check if the fields are empty in flash <?php $sendto = 'xyz@domain.com.au'; $subject = 'Message From XXXYYYZZZ'; $name = $_POST['fromname']; $from = $_POST['fromemail']; $phone = $_POST['fromphone']; $message = $_POST['frommessage']; $message = stripslashes($message); $content = "IP: " . $_SERVER['REMOTE_ADDR'] . "\n"; $content = "Name: " . $name . "\n"; $content .= "Email: " . $from . "\n\n"; $content .= "Phone: " . $phone . "\n\n"; $content .= $message; //if(mail($sendto,$subject,$content)) if(empty($name ) || empty($email) || empty ($phone) || empty ($message)) { echo 'response=failed'; } elseif(mail($sendto,$subject,$content)) { echo 'response=passed'; } ?> <?php //original code //$sendto = 'xyz@domain.com.au'; //$subject = 'Message From XXXYYYZZZ'; //$name = $_POST['fromname']; //$from = $_POST['fromemail']; //$phone = $_POST['fromphone']; //$message = $_POST['frommessage']; //$message = stripslashes($message); //$content = "Name: " . $name . "\n"; //$content .= "Email: " . $from . "\n\n"; //$content .= "Phone: " . $phone . "\n\n"; //$content .= $message; //if(mail($sendto,$subject,$content)) //{ // echo 'response=passed'; //} //else //{ // echo 'response=failed'; //} ?> Quote Link to comment https://forums.phpfreaks.com/topic/184226-please-help-with-form-field-when-empty-not-to-submit/#findComment-972629 Share on other sites More sharing options...
oavs Posted December 7, 2009 Author Share Posted December 7, 2009 Thank you for your kind help. Form is now not sending at all. Quote Link to comment https://forums.phpfreaks.com/topic/184226-please-help-with-form-field-when-empty-not-to-submit/#findComment-972630 Share on other sites More sharing options...
c-o-d-e Posted December 7, 2009 Share Posted December 7, 2009 Try this mate. <?php $sendto = 'xyz@domain.com.au'; $subject = 'Message From XXXYYYZZZ'; $name = $_POST['fromname']; $from = $_POST['fromemail']; $phone = $_POST['fromphone']; $message = $_POST['frommessage']; $message = stripslashes($message); $content = "Name: " . $ip . "\n"; $content = "Name: " . $name . "\n"; $content .= "Email: " . $from . "\n\n"; $content .= "Phone: " . $phone . "\n\n"; $content .= $message; //if(mail($sendto,$subject,$content)) if(empty($_POST['fromname'])) { $error['fromname'] = 'You need to enter From'; } if(empty($_POST['fromemail'])) { $error['fromemail'] = 'You need to enter your Email'; } if(empty($_POST['fromphone'])) { $error['fromphone'] = 'You need to enter your Phone Number'; } if(empty($_POST['frommessage'])) { $error['frommessage'] = 'You need to enter your Message'; } // All you need to do with them variables is put them anywhere on the page, and the errors will display there //example // echo ''.$error['fromname'].'<br />'.$error['fromemail'].'<br />'; // etc etc // Or you can do it this method // echo $error['fromname']; // then else where on your form for another field // echo $error['fromemail']; if (!isset($error)) { mail($sendto,$subject,$content) echo 'response=passed'; } /* original code $sendto = 'xyz@domain.com.au'; $subject = 'Message From XXXYYYZZZ'; $name = $_POST['fromname']; $from = $_POST['fromemail']; $phone = $_POST['fromphone']; $message = $_POST['frommessage']; $message = stripslashes($message); $content = "Name: " . $name . "\n"; $content .= "Email: " . $from . "\n\n"; $content .= "Phone: " . $phone . "\n\n"; $content .= $message; if(mail($sendto,$subject,$content)) { echo 'response=passed'; } else { echo 'response=failed'; } */ ?> Quote Link to comment https://forums.phpfreaks.com/topic/184226-please-help-with-form-field-when-empty-not-to-submit/#findComment-972637 Share on other sites More sharing options...
oavs Posted December 7, 2009 Author Share Posted December 7, 2009 No difference. Still no emails are sent. It says it is sending when submitted blank or filled in, Quote Link to comment https://forums.phpfreaks.com/topic/184226-please-help-with-form-field-when-empty-not-to-submit/#findComment-972644 Share on other sites More sharing options...
rajivgonsalves Posted December 7, 2009 Share Posted December 7, 2009 the php code was right you would have to modify your flash code accordingly to show the error ? Quote Link to comment https://forums.phpfreaks.com/topic/184226-please-help-with-form-field-when-empty-not-to-submit/#findComment-972755 Share on other sites More sharing options...
oavs Posted December 7, 2009 Author Share Posted December 7, 2009 I have posted the flash email code above your answer. I don't know what else it needs. Quote Link to comment https://forums.phpfreaks.com/topic/184226-please-help-with-form-field-when-empty-not-to-submit/#findComment-973023 Share on other sites More sharing options...
rajivgonsalves Posted December 7, 2009 Share Posted December 7, 2009 you would have to take the response and evaluate it in flash and display the right message, on a side note the php code I provided checks for all the fields to be filled Quote Link to comment https://forums.phpfreaks.com/topic/184226-please-help-with-form-field-when-empty-not-to-submit/#findComment-973041 Share on other sites More sharing options...
oavs Posted December 7, 2009 Author Share Posted December 7, 2009 Hi I am sorry but I don't know how to do that. If you can give me one line of example, may be I can follow and do the rest. I know what you are saying it is just I don't know how to evaluate it in flash as it has functions that not sure how to insert php code into. Quote Link to comment https://forums.phpfreaks.com/topic/184226-please-help-with-form-field-when-empty-not-to-submit/#findComment-973113 Share on other sites More sharing options...
rajivgonsalves Posted December 8, 2009 Share Posted December 8, 2009 take a look here there is an example at the bottom http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLLoader.html Quote Link to comment https://forums.phpfreaks.com/topic/184226-please-help-with-form-field-when-empty-not-to-submit/#findComment-973157 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.