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: [Jason] trouble getting form data to mail.php

Right now we have ~42 categories in CMS and each of those categories has it's own contact page with the email form on it. So in order to be more efficient we have created a mail_2.php page that all of the pages use to send the emails. This saves us time when we want to make changes to the email, etc. So that is why I was redirecting it to there.

We do know now that we have setup our categories in CMS "wrong" from the start by having each category have its own table instead of just one big table with all the 42 categories in it. We are planning right now to begin the process of completely overhauling the system and setting it up the way we should have done from the start. Which will make things like this much easier.

So at this point it may just be easier to append the stuff at the end of mail_2.php. And then once we overhaul everything and have only 1 details viewer rather than 42 of them go ahead and send the email from that 1 page.

Thanks!
Lauren
Jason Glass

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/