trouble getting form data to mail.php

6 posts by 2 authors in: Forums > CMS Builder
Last Post: August 25, 2010   (RSS)

Hello!

We have a contact form on our site. The user fills it out and the form goes to the rental company as well as the user email that they provided. We have a mail.php file that process the form data and sends the emails. This was all working fine but we are adding some elements and now we cannot get the form to function as we want it to.

We have set up a random number generator field to help eliminate some spam. We also have updated the code to make the fields required.

This is what I have found:

This is the form tag that we originally had does not check the new required fields coding. It goes right to the mail_2.php page:
<form action="http://www.ourcompany.com/mail_2.php" name="form1" method="post"><input type="hidden" name="submitForm" value="1" />

After reading some of your forum posts, I found some code and changed the form tags to read:
<form action="?" name="form1" method="post">

This correctly checks for errors but when it "redirects" to the mail.php page it does not seem to take any of the form info with it.

The code for the required fields is:
// process form
if (@$_REQUEST['submitForm']) {

// error checking
$errorsAndAlerts = "";
$check = $_REQUEST['check'];
$randomNumber = $_REQUEST['randomNumber'];

if (!@$_REQUEST['user_email']) { $errorsAndAlerts .= "You must enter your email!<br/>
\n"; }
else if(!isValidEmail(@$_REQUEST['user_email'])) { $errorsAndAlerts .= "Please enter a valid email (example: user@example.com)<br/>
\n"; }

if (!@$_REQUEST['randomNumber']) { $errorsAndAlerts = "Please verify the number!<br/>\n"; }
if (($randomNumber != $check)) { $errorsAndAlerts = "Please enter the number shown!<br/>\n"; }

$requiredFields['user_name'] = 'Name';
$requiredFields['user_email'] = 'Email';
$requiredFields['message'] = 'Message';
$requiredFields['user_phone'] = 'Phone Number';
$requiredFields['agreecheck'] = 'Agree to Privacy Policy';

foreach ($requiredFields as $name => $label) {
if (!$label) { $label = $name; }
if (!@$_REQUEST[$name]) { $errorsAndAlerts .= "You must enter a value for '$label'!<br/>\n"; }
}


// send email
if (!$errorsAndAlerts) redirectBrowserToURL("http://www.rentittoday.com/mail_2.php";)

}


I am beginning to think that maybe we are not "redirecting" it correctly?
// send email
if (!$errorsAndAlerts) redirectBrowserToURL("http://www.rentittoday.com/mail_2.php";)


If anyone has any ideas they would be greatly appreciated!

Thank you,
Lauren
Jason Glass

Re: [rentittoday] trouble getting form data to mail.php

By Jason - August 23, 2010

Hi Lauren,

You are redirecting correctly. The issue is that when you redirect, it doesn't bring any of the form elements with it.

Why do you need to do the redirect? Is it possible to send the email from the page that you have doing the error checking? This would be the quickest and simplest solution.
Another solution would be to append all of the variables to the end of mail_2.php where you do the redirect.

Let me know and I can give you some more specific examples.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [rentittoday] trouble getting form data to mail.php

By Jason - August 23, 2010

Hi Lauren,

I see. In this case, you can use this code to append all of the variables in the $_REQUEST array to the end of your URL.

$url=""http://www.rentittoday.com/mail_2.php?";

foreach($_REQUEST as $key => $value){
$url.="$key=$value&";
}


// send email
if (!$errorsAndAlerts) redirectBrowserToURL($url);


Give that a try.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] trouble getting form data to mail.php

By rentittoday - August 25, 2010 - edited: August 25, 2010

That works beautifully! Thank you.

Now the issue is that the email we send out is UGLY!

The fields do not always align in the email that is sent. For example, they align in outlook express but not when you view it in gmail.

We would also like to add an image of our logo at the end of the message. What are the easiest ways to accomplish these tasks?

I have attached a file of our mail_2.php which is the file that generates the emails.

Thanks!
Jason Glass
Attachments:

mail_2.php 2K

Re: [rentittoday] trouble getting form data to mail.php

By Jason - August 25, 2010

Hi,

If you`re just sending your email as plain text, there really isn`t a way to control how different email applications display it.

If you want to add an image to your email, you need to be sending your email as HTML. This will also give you a greater degree of control on how it looks. Take a look at this post to see how to send that kind of email:
http://www.interactivetools.com/forum/gforum.cgi?post=81273#81273

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/