We have a form that sends an email to a mailchimp list and our SMS lists. The form works fine but we need it to have all of the fields required. I have tried for 6 hours to make this work and I can't figure it out. Here is the code, the username and password for the SMS and the link to the mailchimp account are not the real ones.
here is the HTML:
<h3>Instant Text and Email Messaging</h3>
<div id="text_mail_form" align="center">
<form id="txt-email-form" method="post">
<table width="300" border="0">
<tr>
<td colspan="2">
<div id="emailresult" style="color:green;">
<?php
if ($_POST)
{
echo $msg;
} else {
echo $msg;
}
?>
</div>
</td>
<tr>
<td colspan="3">
<input type="radio" name="longshort" value="Long" /> Long
<input type="radio" name="longshort" value="Short" /> Short
<input type="radio" name="longshort" value="Closed Trade" /> Closed Trade
</td>
</tr>
<tr>
<td style="width:150px;">Symbol:</td>
<td>
<input type="text" val="'xyz'" onclick="this.value='';" name="symbol" class="required"/></td>
</tr>
<tr>
<td>Shares:</td>
<td><input type="text" name="shares" class="required" /></td>
</tr>
<tr>
<td>Price:</td>
<td><input type="text" name="price" class="required" /></td>
</tr>
<tr>
<td colspan="2">
<textarea cols="48" rows="3" onfocus="this.value='';" style="font-style:italic;" name="comments" class="required" />Comments</textarea>
</td>
</tr>
<tr>
<td><input type="submit" value="Send Msg to Txt and Email" />
</td>
<td> </td>
</tr>
</table>
</form>
</div>
<br/>
here is the PHP:
<script>
jQuery(document).ready(function($) {
$('#txt-email-form').submit(function(e) {
var postData = $(this).serializeArray();
var formURL = $(this).attr("action");
var url = ''
$.ajax(
{
url : 'http://www.stockaviator.com' + window.location.pathname,
type: "POST",
data : postData,
success:function(data, textStatus, jqXHR)
{
$('#txt-email-form input[type=text]').val('');
$('#txt-email-form textarea').val('');
},
error: function(jqXHR, textStatus, errorThrown)
{
//if fails
}
});
e.preventDefault(); //STOP default action
e.unbind(); //unbind. to stop multiple form submit.
});
});
</script>
<?php
//create full width template
kleo_switch_layout('no');
?>
<?php
if ($_POST)
{
if ( $_POST['longshort'] == 'Long' ) {
$buy = "bought";
} elseif ( $_POST['longshort'] == 'Short' ) {
$buy = "shorted";
} elseif ( $_POST['longshort'] == 'Closed Trade' ) {
$buy = "closed trade";
}
$subject = "StockAviator Trade Alert: ".strtoupper($_POST["symbol"]);
$body = " StockAviator ".$buy." ".$_POST["shares"]." shares of ".strtoupper($_POST["symbol"]). " at $".$_POST["price"].".";
$body2 = $body;
$body = urlencode($body);
if ($_POST["comments"])
{
$body .= " ".urlencode($_POST["comments"]);
$body2 .= " ".$_POST["comments"];
}
//msg to optit
$url = "http://api.optitmobile.com/1/sendmessage/keywords.json";
$myvars = "keyword_id=183&title=".$subject."&message=".$body;
//echo $url.$myvars;
$username = "username";
$password = "password";
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_POSTFIELDS, $myvars);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
$html = curl_exec($process);
curl_close($process);
$msg = json_decode($html, true);
//email to mailchimp
$to = "example@example.com";
$subject = $subject;
$message = $body2;
$header = "From: StockAviator <example2@example.com>\r\n";
$retval = wp_mail($to,$subject,$message,$header);
if( $retval == true )
{
$msg .= "Message sent successfully...";
}
else
{
$msg .= "Message could not be sent...";
}
}
?>
This is on a wordpress site, the PHP is in a page template and the HTML is in a sidebar as we have several different forms for different people to use. The form must clear after submission and NOT refresh the page as they stay on the page and use the form several times throughout the day.
Please Help! I'm new to this forum so if this is too much and I should hire someone, please tell me, we're happy to pay someone but having a hard time finding an honest and capable coder!
Thanks