Trying to merge addform and mailform

9 posts by 3 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: April 5, 2012   (RSS)

I just want to send the the admin an email and copy of whatever was posted.

I am confused on how where I add things ..everything I try it never shows the page.

and I am confused as one says

// process form
if (@$_REQUEST['submitForm']) {

and the other says

// submit form
if (@$_REQUEST['submit']) {

which do I use ?

Here is my working addform



<?php
require_once "cmsAdmin/lib/viewer_functions.php";
if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); }


// submit form
if (@$_REQUEST['submit']) {

// error checking
$errorsAndAlerts = "";
if ([url "mailto:!@$_REQUEST['priority'"]!@$_REQUEST['priority'[/url]]) { $errorsAndAlerts .= "Please specify priority!<br/>\n"; }
if ([url "mailto:!@$_REQUEST['name'"]!@$_REQUEST['name'[/url]]) { $errorsAndAlerts .= "Please specify name!<br/>\n"; }
if ([url "mailto:!@$_REQUEST['address'"]!@$_REQUEST['address'[/url]]) { $errorsAndAlerts .= "Please specify address!<br/>\n"; }
if ([url "mailto:!@$_REQUEST['city'"]!@$_REQUEST['city'[/url]]) { $errorsAndAlerts .= "Please specify city!<br/>\n"; }
if ([url "mailto:!@$_REQUEST['state'"]!@$_REQUEST['state'[/url]]) { $errorsAndAlerts .= "Please specify state!<br/>\n"; }
if ([url "mailto:!@$_REQUEST['zip'"]!@$_REQUEST['zip'[/url]]) { $errorsAndAlerts .= "Please specify zip!<br/>\n"; }
if ([url "mailto:!@$_REQUEST['email'"]!@$_REQUEST['email'[/url]]) { $errorsAndAlerts .= "Please specify email!<br/>\n"; }
if ([url "mailto:!@$_REQUEST['contact_phone'"]!@$_REQUEST['contact_phone'[/url]]) { $errorsAndAlerts .= "Please specify contact phone!<br/>\n"; }


// turn off strict mysql error checking for: STRICT_ALL_TABLES
mysqlStrictMode(false); // disable Mysql strict errors for when a field isn't defined below (can be caused when fields are added later)

// add record
if (!@$errorsAndAlerts) {
mysql_query("INSERT INTO `{$TABLE_PREFIX}auto_referrals` SET
priority = '".mysql_real_escape_string( $_REQUEST['priority'] )."',
name = '".mysql_real_escape_string( $_REQUEST['name'] )."',
address = '".mysql_real_escape_string( $_REQUEST['address'] )."',
city = '".mysql_real_escape_string( $_REQUEST['city'] )."',
state = '".mysql_real_escape_string( $_REQUEST['state'] )."',
zip = '".mysql_real_escape_string( $_REQUEST['zip'] )."',
contact_phone = '".mysql_real_escape_string( $_REQUEST['contact_phone'] )."',
email = '".mysql_real_escape_string( $_REQUEST['email'] )."',
date_of_loss = '".mysql_real_escape_string( $_REQUEST['date_of_loss'] )."',
vehicle_make = '".mysql_real_escape_string( $_REQUEST['vehicle_make'] )."',
vehicle_model = '".mysql_real_escape_string( $_REQUEST['vehicle_model'] )."',
vehicle_year = '".mysql_real_escape_string( $_REQUEST['vehicle_year'] )."',
notes = '".mysql_real_escape_string( $_REQUEST['notes'] )."',



createdDate = NOW(),
updatedDate = NOW(),
createdByUserNum = '".mysql_escape($CURRENT_USER['num'])."',
updatedByUserNum = '".mysql_escape($CURRENT_USER['num'])."'")
or die("MySQL Error Creating Record:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
$recordNum = mysql_insert_id();

// display thanks message and clear form
$errorsAndAlerts = "Thanks, we've added that referral! <br/>
<a href='{$GLOBALS['WEBSITE_LOGIN_POST_LOGIN_URL']}'>Click here to continue</a>";
$_REQUEST = array();
}

}

?>



<div align="center">
<br>
&nbsp;<table border="1" width="80%" id="table1" bordercolor="#000000">
<tr>
<td>


<div align="center">
<form method="post" action="">
<input type="hidden" name="submit" value="1" />

<p align="center"><font face="Verdana"><b>Please Add Your Referral<br/> </b></font>


<?php if (@$errorsAndAlerts): ?>
<br>
&nbsp;<div style="color: red; font-weight: bold; font-size: 16px;"><br/> <?php echo $errorsAndAlerts; ?>&nbsp; </div>
<?php endif ?>
<br/>
<table border="0" cellspacing="0" cellpadding="2" width="50%" id="table2">
<tr>
<td valign="top" width="30%"><b><font size="2" face="Verdana">Priority</font></b></td>
<td><select name="priority" class="dropdown" id="type" size="1" style="font-family: Verdana; color: #000000; font-size: 10pt" >
<option selected>Select Priority</option>
<?php
$schema = loadSchema('auto_referrals');
$fieldSchema = $schema['priority'];
$fieldOptions = getListOptionsFromSchema($fieldSchema);

foreach ($fieldOptions as $valueAndLabel) {
list($value,$label) = $valueAndLabel;
$encodedValue = htmlspecialchars($value);
$encodedLabel = htmlspecialchars($label);
print "<option value=\"$encodedValue\">$encodedLabel</option>\n";
}
?>

</select></td>
</tr>
<tr>
<td valign="top" width="30%"><font face="Verdana" size="2"><b>Name</b></font></td>
<td>
<input type="text" name="name" value="<?php echo htmlspecialchars(@$_REQUEST['name']) ?>" size="60" /></td>
</tr>
<tr>
<td valign="top" width="30%"><font face="Verdana" size="2"><b>Address</b></font></td>
<td><input type="text" name="address" value="<?php echo htmlspecialchars(@$_REQUEST['address']) ?>" size="60" /></td>
</tr>
<tr>
<td valign="top" width="30%"><font face="Verdana" size="2"><b>City</b></font></td>
<td><input type="text" name="city" value="<?php echo htmlspecialchars(@$_REQUEST['city']) ?>" size="60" /></td>
</tr>
<tr>
<td valign="top" width="30%"><font face="Verdana" size="2"><b>State</b></font></td>
<td><input type="text" name="state" value="<?php echo htmlspecialchars(@$_REQUEST['state']) ?>" size="60" /></td>
</tr>
<tr>
<td valign="top" width="30%"><font face="Verdana" size="2"><b>Zip</b></font></td>
<td><input type="text" name="zip" value="<?php echo htmlspecialchars(@$_REQUEST['zip']) ?>" size="60" /></td>
</tr>
<tr>
<td valign="top" width="30%"><font face="Verdana" size="2"><b>Contact Phone</b></font></td>
<td><input type="text" name="contact_phone" value="<?php echo htmlspecialchars(@$_REQUEST['contact_phone']) ?>" size="60" /></td>
</tr>
<tr>
<td valign="top" width="30%"><b><font face="Verdana" size="2">Email</font></b></td>
<td><input type="text" name="email" value="<?php echo htmlspecialchars(@$_REQUEST['email']) ?>" size="60" /></td>
</tr>
<tr>
<td valign="top" width="30%"><b><font face="Verdana" size="2">Date of Loss</font></b></td>
<td><input type="text" name="date_of_loss" value="<?php echo htmlspecialchars(@$_REQUEST['date_of_loss']) ?>" size="60" /></td>
</tr>
<tr>
<td valign="top" width="30%"><font face="Verdana" size="2"><b>Vehicle make</b></font></td>
<td><input type="text" name="vehicle_make" value="<?php echo htmlspecialchars(@$_REQUEST['vehicle_make']) ?>" size="60" /></td>
</tr>
<tr>
<td valign="top" width="30%"><b><font face="Verdana" size="2">V</font></b><font face="Verdana" size="2"><b>ehicle model</b></font></td>
<td><input type="text" name="vehicle_model" value="<?php echo htmlspecialchars(@$_REQUEST['vehicle_model']) ?>" size="60" /></td>
</tr>
<tr>
<td valign="top" width="30%"><b><font face="Verdana" size="2">V</font></b><font face="Verdana" size="2"><b>ehicle year</b></font></td>
<td><input type="text" name="vehicle_year" value="<?php echo htmlspecialchars(@$_REQUEST['vehicle_year']) ?>" size="60" /></td>
</tr>
<td valign="top" width="30%"><font face="Verdana" size="2"><b>Notes</b></font></td>
<td><textarea name="notes" cols="37" rows="4"><?php echo htmlspecialchars(@$_REQUEST['notes']) ?></textarea></td>
</tr>

</table></div>
<p align="center">


<input type="submit" name="add" value="Add Referral &gt;&gt;" />
</form>
<br>
&nbsp;</p>
</td>
</tr>
</table>
<p align="center">&nbsp;</div>
Patricia

www.thenetgirl.com

Re: [thenetgirl] Trying to merge addform and mailform

By Jason - April 2, 2012

Hi,

You would use:

if (@$_REQUEST['submit'])

because in your form you have this hidden field:

<input type="hidden" name="submit" value="1" />

so the if statement is just looking to see if there is a value in that variable. If there is, it means the form had been submitted.

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] Trying to merge addform and mailform

By thenetgirl - April 2, 2012

Thanks so in the addform where would I put this ?



// send email user
if (!$errorsAndAlerts) {
$from = $_REQUEST['email'];
$to = "patricia@thenetgirl.com";
$subject = "Email form submitted from {$_SERVER['HTTP_HOST']}";
$message = <<<__TEXT__
You've received an email from the email form here:
[url "http://{$_SERVER['HTTP_HOST']}{$_SERVER['SCRIPT_NAME'"]http://{$_SERVER['HTTP_HOST']}{$_SERVER['SCRIPT_NAME'[/url]]}

Full name: {$_REQUEST['fullname']}
Email: {$_REQUEST['email']}
Message: {$_REQUEST['message']}

The user who sent this message had the IP address {$_SERVER['REMOTE_ADDR']}.
__TEXT__;

// send message
$mailResult = @mail($to, $subject, $message, "From: $from");
if (!$mailResult) { die("Mail Error: $php_errormsg"); }

//
$errorsAndAlerts = "Thanks! We've sent your email.";
$_REQUEST = array(); // clear form values
}

}
Patricia

www.thenetgirl.com

Re: [thenetgirl] Trying to merge addform and mailform

By (Deleted User) - April 3, 2012

Hi thenetgirl,

That would probably best sit after the
$recordNum = mysql_insert_id();

You wouldn't need to wrap it in the "if (!$errorsAndAlerts) { " as that's already been checked before the insert is done.

Let me know if this helps,

Tom

Re: [Tom P] Trying to merge addform and mailform

By thenetgirl - April 3, 2012

No Matter where I put it I get a blank page
Patricia

www.thenetgirl.com

Re: [thenetgirl] Trying to merge addform and mailform

By (Deleted User) - April 4, 2012

Hi,

Do you get a blank page after submitting the form or just when trying to load the page?

If you could attach the code for the entire page I could have a quick look over and see if there is anything stopping the page from displaying in either case.

Thanks,

Tom

Re: [Tom P] Trying to merge addform and mailform

By thenetgirl - April 4, 2012

I got it to post amd mail finally but the email is coming from my apache server and I dont know how to fix that
Patricia

www.thenetgirl.com
Attachments:

medical_addform.php 7K

Re: [Tom P] Trying to merge addform and mailform

By thenetgirl - April 5, 2012

well thanks for the advice but think I let it be ..I host there site but not heir email.
Patricia

www.thenetgirl.com