Jump to content

Please help with form field when empty not to submit


oavs

Recommended Posts

Hi  :confused: ,

 

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  :D

 

<?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';

//}

 

?>

Link to comment
Share on other sites

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.";

}

Link to comment
Share on other sites

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';
//}

?>

Link to comment
Share on other sites

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';
} */

?>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.