I am creating a job application form which has a drop down box that the user can select a city from and continue filling out the form. The objective here is depending on what city the user selected and then submits the form, it will be sent to an email address assigned to the value of that option. I have successfully been able to make this work on just simple form fields like "Name, email, and message". However since I have actually started creating the form and many more form fields it is no longer working. I have worked with a couple of tests, one using print_r($_POST);. After submitting the form it will display all of the form values that was sent, but not mail those results using mail() function. php code is below:
<?php
//Sanatize field inputs
if(isset($_POST['post'])) {
// check reCAPTCHA information
require_once('recaptchalib.php');
$privatekey = "6LcuhsgSAAAAAJ1Xlct4dmqOT2SnlhOuwAEImAXH ";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
// if CAPTCHA is correctly entered!
if ($resp->is_valid) {
$headers = "From: $email\r\n";
$headers = "Reply-To: $email\r\n";
$headers = "MIME-Version: 1.0\r\n";
$headers = "subject: Application\r\n";
$headers = "Content-Type: text/html; charset=utf-8\r\n";
$cities = $_POST['cities'];
$lastname = filter_var($_POST['lastname'], FILTER_SANITIZE_STRING);
$firstname = filter_var($_POST['firstname'], FILTER_SANITIZE_STRING);
$middle = filter_var($_POST['middle'], FILTER_SANITIZE_STRING);
$street = filter_var($_POST['street'], FILTER_SANITIZE_STRING);
$city = filter_var($_POST['city'], FILTER_SANITIZE_STRING);
$state = filter_var($_POST['state'], FILTER_SANITIZE_STRING);
$zip = filter_var($_POST['zip'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['email'], FILTER_SANITIZE_STRING);
$hphone = filter_var($_POST['hphone'], FILTER_SANITIZE_STRING);
$cphone = filter_var($_POST['cphone'], FILTER_SANITIZE_STRING);
$social = filter_var($_POST['social'], FILTER_SANITIZE_STRING);
$referral = filter_var($_POST['referral'], FILTER_SANITIZE_STRING);
$position = filter_var($_POST['position'], FILTER_SANITIZE_STRING);
$pay = filter_var($_POST['pay'], FILTER_SANITIZE_STRING);
$message = "
New mail from:<br><br>
Name: $firstname $lastname <br>
Email: $email <br>
Message: $position <br >
$pay";
//$to = "testing#website.com";
//Here I provide the email address for cities
$email1 = "testin1g#website.com";
$email2 = "testing2#website.com";
$email3 = "testing3#website.com";
//print_r($_POST);
// Logic for getting the value of drop down and then sending mail.
if ($cities == "NY"){
$sendMail = mail($email1, $message, $headers);
if($sendMail) {
echo 'Thank you ' .$firstname. ', the mail has been successfully sent!<br><br>';
} else {
echo 'An error occured and the mail could not be sent.<br>
Please try again later.';
}
}
elseif ($cities == "NC"){
$sendMail = mail($email2, $message, $headers);
if($sendMail) {
echo 'Thank you ' .$firstname. ', the mail has been successfully sent!<br><br>';
} else {
echo 'An error occured and the mail could not be sent.<br>
Please try again later.';
}
} elseif ($cities == "TX"){
$sendMail = mail($email3, $message, $headers);
if($sendMail) {
echo 'Thank you ' .$firstname. ', the mail has been successfully sent!<br><br>';
} else {
echo 'An error occured and the mail could not be sent.<br>
Please try again later.';
}
} elseif ($cities == "ME"){
$sendMail = mail($email1, $message, $headers);
if($sendMail) {
echo 'Thank you ' .$firstname. ', the mail has been successfully sent!<br><br>';
} else {
echo 'An error occured and the mail could not be sent.<br>
Please try again later.';
}
}
} else {
// handle the CAPTCHA being entered incorrectly
echo 'You Did not enter the CAPTCHA in correctly. Please go back and do so.';
}
}
session_destroy();
?>
As you can see above I have a couple of email addresses listed and then using the if statement I am telling php if the "cities = state" to send to that email address. However this is the part it is getting hung up on. It is going straight to my error message.
And my html form:
<form method="post" action="../sendemail.php">
<table cellpadding="0" cellspacing="0" width="900">
<tr>
<td width="800" bgcolor="White">
<div id="copyContainerwide">
<h1>NexxLinx Career Opportunities</h1>
<p>
Thank you for your interest in a career with NexxLinx! We have many different opportunities for employment, which may vary depending
upon which center you are interested in applying for. For more information on what positions we have available, please contact your local
NexxLinx centers, or visit us in person! </p>
<br/>
<p>To apply please select the center you would like to apply to:</p>
<select name="cities">
<option value="NY">Newburgh, NY</option>
<option value="NC">Jacksonville, NC</option>
<option value="TX" >Austin, TX</option>
<option value="ME">Orono, ME</option>
<option value="UT">South Jordan, UT</option>
</select>
<br/>
<p> TO THE APPLICANT: You must fully complete this application for it to be considered. Applications are active for ninety (90) days;
thereafter, you must personally renew the application to be considered for employment. We provide equal opportunities to all applicants
and employees without regard to race, color, religion, sex, national origin, age, or disability, in accordance with applicable federal
and state laws. Accommodation is available to applicants with a disabling condition, when applying, testing, or interviewing for a position.
Please contact the Human Resource Department to request accommodation.</p>
<fieldset>
<legend>General Information </legend>
<table>
<tr>
<td>Last Name:<br/>
<input name="lastname" type="text" size="30" /></td>
<td> First Name:<br/>
<input name="firstname" type="text" size="30"/></td>
<td> Middle Name:<br/>
<input name="middle" type="text" size="30"/></td>
</tr>
</table>
<table>
<tr>
<td>Street Address<br/>
<input name="street" type="text" size="50" /></td>
<td> City<br/>
<input name="city" type="text" size="30" /></td>
<td>State (abbr.)<br/>
<input name="state" type="text" size="7" /></td>
<td> Zip Code <br/>
<input name="zip" type="text" size="12" /></td>
</tr>
</table>
<table>
<tr>
<td>E-mail:<br/>
<input name="email" type="email" size="50" /></td>
<td>Home Phone:<br/>
<input name="hphone" type="tel" size="15" /></td>
<td>Cell Phone:<br/>
<input name="cphone" type="tel" size="15" /></td>
<td>Social Security Number<br/>
<input name="social" type="text" size="12" /></td>
</tr>
</table>
<table>
<tr>
<td>Referred By:</td>
<td><input name="agency" type="checkbox" />Agency</td>
<td><input name="advert" type="checkbox" />Advertisement</td>
<td><input name="employee" type="checkbox" />Empoloyee</td>
<td><input name="other" type="checkbox" />Other</td>
</tr>
<table>
<tr>
<td>Please list the name of the above agency, publication with the advertisement, employee, or other referall.<br/>
<input name="referral" type="text" size="60" /></td>
</tr>
</table>
<table>
<tr>
<td>Position Applied For:<br/>
<input name="position" type="text" size="50"/></td>
<td>Pay Desired:<br/>
$<input name="pay" type="text" size="20" /></td>
</tr>
<tr>
<td>
<?php
require_once('../recaptchalib.php');
$publickey = "6LcuhsgSAAAAAHtXF5i5f5XEAZmjyAtYvHGGQlhf ";
echo recaptcha_get_html($publickey);
?>
</td>
</tr>
<tr>
<td>
<input type="submit" name="post" value="submit" />
</table>
</fieldset>
</div>
</td>
</tr>
</table>
</form>
Thanks for any advice you can give me!
UPDATE:
Finally have this working! Thank you everyone for the help. For what ever reason and please correct if this is not right, I moved my headers up at the top of all of my other variables and it now works like a charm. FYI: I was working on this locally with WAMP and had a dumby sendmail configured to send through my gmail account. It work with very simple forms but apparently this one was a little too advanced, so I finally uploaded and finished testing it on my live server.
Something extra that maybe someone can help me with is validating a social security number and show the * when someone inters in numbers. Can that be done with javascript?
why not assign the email address to the value of the area if you can always reverse if your going to insert it in the database it like
<select name="cities">
<option value="test1#yahoo.com">Newburgh, NY</option>
<option value="test2#yahoo.com">Jacksonville, NC</option>
<option value="test3#yahoo.com" >Austin, TX</option>
</select>
$to=$_POST['cities'];
mail('$to', '$subject', '$message);
if you need to insert the location in database just reverse it
if($citiies==test1#yahoo.com)
{
//insert into database NY
}
this code is shorter and looks cleaner but you will need to if else it again if your going to store the
location in the database
it will be shorter because you will not compare values just send it to what the value assign is
Related
I'm back again. Here is the issue. In implementing ReCaptcha 2.0, I've downloaded file from Github and did all that was instructed (well apparently not or I wouldn't have an issue). My form automatically loads with error showing "missing-input-response" right above the submit button. I can, however, fill out and submit the form and it redirects to the "thank you" page. If I try to submit the form without checking the box, it gives the error (which is good) but the error is there no matter what. What do I need to do? I would really appreciate any help.
Here is my code:
<?php
require('recaptcha-master/src/autoload.php');
$siteKey = 'MY SITE KEY';
$secret = 'MY SECRET KEY';
$recaptcha = new \ReCaptcha\ReCaptcha($secret, new \ReCaptcha\RequestMethod\SocketPost());
$gRecaptchaResponse = $_POST['g-recaptcha-response']; //google captcha post data
$remoteIp = $_SERVER['REMOTE_ADDR']; //to get user's ip
$recaptchaErrors = ''; // blank variable to store error
$resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp); //method to verify captcha
if ($resp->isSuccess()) {
// send mail or insert in db or do whatever you wish to
$emailbody = 'Name: '.$_POST['name']."\n"
.'Phone: '.$_POST['phone']."\n"
.'Email: '.$_POST['email']."\n"
.'Message: '.$_POST['message'];
mail('newsong80#maxxsouth.net', 'More Information', $emailbody);
echo "<meta http-equiv='refresh' content=\"0; url=thankyou.php\">";
} else {
$recaptchaErrors = $resp->getErrorCodes(); // set the error in varible
}
?>
**Here is my form:**
<form action="contact.php" method="POST" title="Contact us for more information">
<p><b>Name:<br>
</b>
<input name="name" type="text" required id="name" tabindex="1" value="" size="50" maxlength="50"/>
<br/> Phone:
<br>
<input name="phone" type="text" id="phone" tabindex="2" value="" size="50" maxlength="50"/><br/>
<b>E-mail:</b><br>
<input name="email" type="text" id="email" tabindex="3" value="" size="50" maxlength="25"/><br/>
<br>
<b>Message:</b><br/>
<textarea name="message" cols="60" rows="10" maxlength="150" id="message" tabindex="4"></textarea><br>
<br>
<div class="g-recaptcha" data-sitekey="MY SITE KEY"></div>
<br>
<?php
if ( isset( $recaptchaErrors[ 0 ] ) )
echo $recaptchaErrors[ 0 ];
?>
<p> </p>
<p><input name="submit" type="submit" formmethod="POST" onClick="MM_validateForm('name','','R','phone','','NisNum','email','','RisEmail','message','','R');return document.MM_returnValue" value="Submit">
</p>
</form>
I found this which is working.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://www.google.com/recaptcha/api/siteverify?");
curl_setopt($ch, CURLOPT_POST, 1);
$campos=array('secret'=>$secreto,'response'=>$TheResponse);
curl_setopt($ch, CURLOPT_POSTFIELDS,$campos);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$ch_exec = curl_exec($ch);
$respuesta_google = json_decode($ch_exec,true);
var_dump($ch_exec);
var_dump($respuesta_google);
curl_close ($ch);
Im having a little issue with my registration script.
I am trying to add rows into my mysql database.
This is my form verifier to make sure all fields are filled:
//Variables from the table
$user = $_POST['un'];
$pass = $_POST['pw'];
$rpass = $_POST['rpw'];
//Prevent MySQL Injections
$user = stripslashes($user);
$pass = stripslashes($pass);
$rpass = stripslashes($rpass);
$user = mysqli_real_escape_string($user);
$pass = mysqli_real_escape_string($pass);
$rpass = mysqli_real_escape_string($rpass);
//Check to see if the user left any space empty!
if($user == "" || $pass == "" || $rpass == "")
{
echo "Please fill in all the information!";
}
and this is the form
<form action="register_proc.php" method="post">
<label for="un">Username</label>
<input type="text" name="un" id="un" placeholder="username"/>
<br/>
<label for="pw">Password</label>
<input type="password" name="pw" id="pw" placeholder="password"/>
<br/>
<label for="rpw">Repeat Password</label>
<input type="password" name="rpw" id="rpw" placeholder="repeat password"/>
<br/>
<input type="submit" name="submit" value="Complete Registration"><br>
<div style="float: left;">
Home
</div>
<div style="float: right;">
Login
</div>
</form>
I have no idea why it keeps outputting the else statment "Please fill in all the information!"
All of the $post variables have the correct names
thank you for the upcoming support.
I've spent most of today and all of yesterday just trying to get a simple, basic send-to-email PHP code to work. Here is the code I've tried putting together myself after extensively researching, checking, and editing based on a lot of other threads I've read on this website and on other sites.
<?php
$to='dustedpages#gmail.com';
$subject='Commission Inquiry';
$email = $_REQUEST['Email'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
$message="Name: ".$name. "\r\n" . "Email: " .$email . "\r\n" . "Username: " .$user . "\r\n" . "Type: ".$position. "\r\n" . "Add-Ons: ".$addons. "\r\n" . "Price: ".$price. "\r\n" . "Brief Description: ".$briefdesc;
$name=$_POST['FirstName'],['LastName'];
$email=$_POST['Email'];
$user=$_POST['User'];
$position=$_POST['position'];
$addons=$_POST['cat'],['dog'];
$price=$_POST['price'];
$desc=$_POST['briefdesc'];
if($sent)
{print "Your mail was sent successfully. Please be patient and the artist will contact you soon. Thanks!"; }
else
{print "We encountered an error sending your mail"; }
?>
There is actually a LOT more form data than just that basic information, but I cannot even get the basic information to show up. For the portion of html codes it is pulling from, here is some of what it looks like.
<!--NAME-->
</li> <li id="li_2" >
<label class="description" for="element_2">Name </label>
<span>
<input onkeypress="return handleEnter(this, event)" id="element_2_1" name="FirstName" class="element text" maxlength="255" size="14" value=""/>
<label>First</label>
</span>
<span>
<input onkeypress="return handleEnter(this, event)" id="element_2_2" name="LastName" class="element text" maxlength="255" size="18" value=""/>
<label>Last</label>
</span>
<p class="guidelines" id="guide_2"><small>Please fill this in as the name I will see on Paypal.</small></p>
<!--EMAIL-->
</li> <li id="li_1" >
<label class="description" for="element_1">Email </label>
<div>
<input onkeypress="return handleEnter(this, event)" id="element_1" name="Email" class="element text medium" type="text" maxlength="255" value=""/>
</div>
<p class="guidelines" id="guide_1"><small>Your Paypal email</small></p>
<!--USERNAME-->
</li> <li id="li_3" >
<label class="description" for="element_3">DA/Tumblr Username </label>
<div>
<input onkeypress="return handleEnter(this, event)" id="element_3" name="User" class="element text medium" type="text" maxlength="255" value=""/>
</div>
<p class="guidelines" id="guide_3"><small>If you have an account on either Deviantart or Tumblr and wish to be credited in the commission description, please note it here.</small></p>
</li>
<p>
<!--POSITION TYPE-->
</li> <li id="li_26" >
<label class="description" for="element_26">Comm. Type </label>
<div>
<select class="element select medium" id="element_26" name="position">
<option value="" selected="selected"></option>
<option value="1" >Bust</option>
<option value="2" >Waist</option>
<option value="3" >Full-Body</option>
</select>
</div>
<p class="guidelines" id="guide_26">
<small>Please choose what position you wish for your character(s) to be viewed from. Price will change depending on what type you choose.</small></p>
<!--ADD ONS-->
</li> <li id="li_27" >
<label class="description" for="element_27" name="addons">Add-Ons </label>
<span>
<input name="cat" type="checkbox" onClick="return KeepCount()">
+1 Character<br>
<input name="dog" type="checkbox" onClick="return KeepCount()">
+2 Characters
I have multiple fields (such as the First and Last Name) that I need to be one single variable in the email code, and I need to be able to display all of the filled out form fields in an email. I can't even get more than one variable to show up at this point.
Also the form itself includes selects, checkboxes, textareas, and image uploads. I haven't even gotten to that point - I'm just trying to make some of the basic information show up right now. I'm very familiar with HTML and Javascript, just not so much PHP, though I've worked with it before. Some of the form data is used in Javascript code on the same page as the HTML, also. The actual PHP data is on a separate file that my form pulls from.
I think what's happening is you're attempting to use variables before they have the value you would like. Try something like the following and let me know how it goes.
<?php
$to = 'dustedpages#gmail.com';
$subject = 'Commission Inquiry';
$headers = "From: $email";
$fname = $_POST['FirstName'];
$lname = $_POST['LastName'];
$email = $_POST['Email'];
$user = $_POST['User'];
$position = "CHANGE-ME";
$addons = "CHANGE-ME";
$price = "CHANGE-ME";
$briefdesc = "CHANGE-ME";
$message = "Name: ".$fname.", ".$lname."\r\n";
$message .= "Email: $email \r\n";
$message .= "Username: $user \r\n";
$message .= "Type: $position \r\n";
$message .= "Add-Ons: $addons \r\n";
$message .= "Price: $price \r\n";
$message .= "Brief Description: $briefdesc \r\n";
$sent = mail($to, $subject, $message, $headers);
if($sent) {
echo "Success";
}
else {
echo "Failure";
}
?>
[[UPDATED AGAIN]] And I am sorry if this question gets wordy.
I am a hobby coder, and I am looking for some help with syntax and functionality within javaScript which will allow copied delimiters such as "\t" and "\n" to skip appropriate <input>'s in an online form.
I think I am about 33% there right now (again: hobby coder - self taught wanna be)
<script type="text/javascript">
function splitInput()
{
var x=document.forms["simpleForm02"]["dataInput_0"].value;
var delimiterT = x.split("\t");
var delimiterN = x.split("\n");
for (var i=0;i<delimiterT.length;i++)
if (x.indexOf("\t") >-1)
{
document.getElementById("dataInput_" + i ).value = (delimiterT[i]);
}
else
for (var i=0;i<delimiterN.length;i++)
if (x.indexOf("\n") >-1)
{
document.getElementById("dataInput_" + (i * 3) ).value = (delimiterN[i]);
}
}
</script>
<form name="simpleForm02">
<table>
<tr>
<th>Color</th>
<th>Model</th>
<th>Qty</th>
</tr>
<tr>
<td><input class="colorInput" id="dataInput_0" name="colorInput_row_1" value="" onKeyUp="splitInput()"></td>
<td><input class="modelInput" id="dataInput_1" name="modelInput_row_1" value="" onKeyUp=""></td>
<td><input class="qtyInput" id="dataInput_2" name="qtyInput_row_1" value="" onKeyUp=""></td>
</tr>
<tr>
<td><input class="colorInput" id="dataInput_3" name="colorInput_row_2" value="" onKeyUp=""></td>
<td><input class="modelInput" id="dataInput_4" name="modelInput_row_2" value="" onKeyUp=""></td>
<td><input class="qtyInput" id="dataInput_5" name="qtyInput_row_2" value="" onKeyUp=""></td>
</tr>
<tr>
<td><input class="colorInput" id="dataInput_6" name="colorInput_row_3" value="" onKeyUp=""></td>
<td><input class="modelInput" id="dataInput_7" name="modelInput_row_3" value="" onKeyUp=""></td>
<td><input class="qtyInput" id="dataInput_8" name="qtyInput_row_3" value="" onKeyUp=""></td>
</tr>
</table>
</form>
This code kinda works, in a limited way. If I copy three excel cells aligned side by side, and paste it into <input class="colorInput" id="dataInput_0" name="colorInput_row_1" value="" onKeyUp="splitInput()">, then the script correctly splits and pastes the contents of the three cells across the top three inputs.
However, I obviously have flaws in the script because it doesn't recognize the '\n' delimiter at all. And I also know that I have coding issues with the circumstance: applying the code to all cells relatively, and not just ["dataInput_0"].
And lets presume I had the following data in an Excel sheet:
I am trying to find functionality that if I copied the Excel sample data above, it would overwrite/write the top 6 of the inputs in the sample <form name="simpleForm">.
Sorry to be long winded.
So, this question has been up for about a week, and during that time I have continued to look for ideas and help.
The solution which has presented to finest potential, but not a complete solution is via the code below:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>
<body>
<script>
function splitInput() {
var x = document.forms["simpleForm02"]["dataInput_0"].value;
if (x.indexOf('\t') > 0) {
var delimiterT = x.split('\t');
for (var i = 0; i < delimiterT.length ; i++)
document.getElementById("dataInput_" + i).value = (delimiterT[i]);
}
else
if (x.indexOf('\n') > 0) {
var delimiterN = x.split('\n');
var j = 0;
for (var i = 0; i < delimiterN.length ; i++) {document.getElementById("dataInput_" + j).value = (delimiterN[i]);
j += 4;
}
}
else
return false;
}
function classFocused() {
var d = document.getElementById("dataInput_0");
d.className = d.className + " InFocus";
}
function classBlured() {
var d = document.getElementById("dataInput_0");
d.className = "inputArea";
}
</script>
<form name="simpleForm02">
<table>
<tr>
<th>Color</th>
<th>Model</th>
<th>Qty</th>
<th>Cost</th>
</tr>
<tr>
<td>
<textarea data-id="0" class="inputArea colorInput" id="dataInput_0" name="colorInput_row_1" onFocus="classFocused();" onBlur="classBlured();" onKeyUp="splitInput();"></textarea>
</td>
<td>
<textarea data-id="1" class="inputArea modelInput" id="dataInput_1" name="modelInput_row_1" onkeyup="" ></textarea></td>
<td>
<textarea data-id="2" class="inputArea qtyInput" id="dataInput_2" name="qtyInput_row_1" onkeyup="" ></textarea></textarea></td>
<td>
<textarea data-id="3" class="inputArea costInput" id="dataInput_3" name="costInput_row_1" onkeyup="" ></textarea></td>
</tr>
<tr>
<td>
<textarea data-id="4" class="inputArea colorInput" id="dataInput_4" name="colorInput_row_2" onkeyup="splitInput()" ></textarea></td>
<td>
<textarea data-id="5" class="inputArea modelInput" id="dataInput_5" name="modelInput_row_2" onkeyup="" ></textarea></td>
<td>
<textarea data-id="6" class="inputArea qtyInput" id="dataInput_6" name="qtyInput_row_2" onkeyup="" ></textarea></td>
<td>
<textarea data-id="7" class="inputArea costInput" id="dataInput_7" name="costInput_row_2" onkeyup="" ></textarea></td>
</tr>
<tr>
<td>
<textarea data-id="8" class="inputArea colorInput" id="dataInput_8" name="colorInput_row_3" onkeyup="splitInput()" ></textarea></td>
<td>
<textarea data-id="9" class="inputArea modelInput" id="dataInput_9" name="modelInput_row_3" onkeyup="" ></textarea></td>
<td>
<textarea data-id="10" class="inputArea qtyInput" id="dataInput_10" name="qtyInput_row_3" onkeyup="" ></textarea></td>
<td>
<textarea data-id="11" class="inputArea costInput" id="dataInput_11" name="costInput_row_3" onkeyup="" ></textarea>
</td>
</tr>
</table>
</form>
</body>
</html>
In the above example of the textarea's, if a '\t' delimiter exists then the split is made and the data is spread over the course of the data's inherit length.
Also, in the above example of the text areas, if a '\n' delimiter exists then the split is made and the data is spread over the course of the data's inherit length vertically instead. The statement: "j += 4" is in essence the number of columns you have in the form.
Though I still need for it to work across all text area inputs, not just the identified as ["dataInput_0"]. A jQuery $(this) identifier maybe?
Also, the coding is limited because if you copy and paste cells which have both \t and \n, then the code doesn't work.
But it is a step in the right direction.
I'm going to do my best to describe what I'm attempting to do, and what I've done, but, please let me know if you need more information to provide help.
What I'm trying to do is create an html table that has 5 columns and any number of rows. It's a very basic order form that will list literature that we have for sale. The first 4 columns provide information about the item, and the 5th column is a simply text input "qty" field that allows a user to enter the "qty" of the item they wish to purchase. You can see what this looks like here: http://web.go-spi.com/cgl/literature/.
It's important to note that the table is generated dynamically, via a custom loop that I've created in Wordpress. I did it this way to allow us to dynamically add or remove literature items from the table.
The code:
<div class='gf_browser_chrome gform_wrapper' id='gform_wrapper_6' >
<a id='gf_6' name='gf_6' class='gform_anchor' ></a>
<form method='post' enctype='multipart/form-data' target='gform_ajax_frame_6' id='gform_6' action='/cgl/literature/#gf_6'>
<div class='gform_body'>
<div id='gform_fields_6' class='gform_fields top_label description_below'>
<?php $literature_query = new WP_Query( array( 'post_type' => 'literature', 'showposts' => '50', 'orderby' => 'meta_value', 'meta_key' => 'ecpt_brochurerow', 'order' => 'ASC'));
if( $literature_query->have_posts() ):?>
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="data">
<thead>
<tr>
<th>Brochure Type</th>
<th><label class='gfield_label' for='input_6_1'>Description</label></th>
<th>Cost</th>
<th>Qty/Pack</th>
<th><label class='gfield_label' for='input_6_2'>Qty</label></th>
</tr>
</thead>
<tbody>
<?php while( $literature_query->have_posts() ): $literature_query->the_post();?>
<tr>
<td><?php echo get_post_meta($post->ID, 'ecpt_brochuregroup', true); ?></td>
<td><?php echo get_post_meta($post->ID, 'ecpt_brochuredescription', true); ?><input type='hidden' class='gform_hidden' name='input_1' id='input_6_1' value="<?php echo get_post_meta($post->ID, 'ecpt_brochuredescription', true); ?>"/></td>
<td><?php echo get_post_meta($post->ID, 'ecpt_brochurecost', true); ?></td>
<td><?php echo get_post_meta($post->ID, 'ecpt_brochureqtyperpack', true); ?></td>
<td><input name='input_2' id='input_6_2' type='text' value='' class='medium'/></td>
</tr>
<?php endwhile;
wp_reset_postdata();
?>
</tbody>
</table>
<?php else: ?>
<div class="alert alert-block">
<p>Sorry, there is currently no literature available. Please check back later.</p>
</div>
<?php endif; ?>
</div>
</div>
<div class='gform_footer top_label'>
<input type='submit' id='gform_submit_button_6' class='button gform_button' value='Submit' tabindex='1' /><input type='hidden' name='gform_ajax' value='form_id=6&title=&description=' />
<input type='hidden' class='gform_hidden' name='is_submit_6' value='1' />
<input type='hidden' class='gform_hidden' name='gform_submit' value='6' />
<input type='hidden' class='gform_hidden' name='gform_unique_id' value='5077469db6b44' />
<input type='hidden' class='gform_hidden' name='state_6' value='YToyOntpOjA7czo2OiJhOjA6e30iO2k6MTtzOjMyOiJjMDlmZjFlZmU1MjMzN2M3M2FkODliMmVjY2Y5YzIxMyI7fQ==' />
<input type='hidden' class='gform_hidden' name='gform_target_page_number_6' id='gform_target_page_number_6' value='0' />
<input type='hidden' class='gform_hidden' name='gform_source_page_number_6' id='gform_source_page_number_6' value='1' />
<input type='hidden' name='gform_field_values' value='' />
</div>
</form>
</div>
<iframe style='display:none;width:0px; height:0px;' src='about:blank' name='gform_ajax_frame_6' id='gform_ajax_frame_6'></iframe>
<script type='text/javascript'>function gformInitSpinner_6(){jQuery('#gform_6').submit(function(){if(jQuery('#gform_ajax_spinner_6').length == 0){jQuery('#gform_submit_button_6').attr('disabled', true).after('<' + 'img id="gform_ajax_spinner_6" class="gform_ajax_spinner" src="/cgl/wp-content/plugins/gravityforms/images/spinner.gif" alt="" />');jQuery('#gform_wrapper_6 .gform_previous_button').attr('disabled', true); jQuery('#gform_wrapper_6 .gform_next_button, #gform_wrapper_6 .gform_image_button').attr('disabled', true).after('<' + 'img id="gform_ajax_spinner_6" class="gform_ajax_spinner" src="/cgl/wp-content/plugins/gravityforms/images/spinner.gif" alt="" />');}} );}jQuery(document).ready(function($){gformInitSpinner_6();jQuery('#gform_ajax_frame_6').load( function(){var contents = jQuery(this).contents().find('*').html();var is_postback = contents.indexOf('GF_AJAX_POSTBACK') >= 0;if(!is_postback){return;}var form_content = jQuery(this).contents().find('#gform_wrapper_6');var is_redirect = contents.indexOf('gformRedirect(){') >= 0;jQuery('#gform_submit_button_6').removeAttr('disabled');var is_form = !(form_content.length <= 0 || is_redirect);if(is_form){jQuery('#gform_wrapper_6').html(form_content.html());jQuery(document).scrollTop(jQuery('#gform_wrapper_6').offset().top);if(window['gformInitDatepicker']) {gformInitDatepicker();}if(window['gformInitPriceFields']) {gformInitPriceFields();}var current_page = jQuery('#gform_source_page_number_6').val();gformInitSpinner_6();jQuery(document).trigger('gform_page_loaded', [6, current_page]);}else if(!is_redirect){var confirmation_content = jQuery(this).contents().find('#gforms_confirmation_message').html();if(!confirmation_content){confirmation_content = contents;}setTimeout(function(){jQuery('#gform_wrapper_6').replaceWith('<' + 'div id=\'gforms_confirmation_message\' class=\'gform_confirmation_message_6\'' + '>' + confirmation_content + '<' + '/div' + '>');jQuery(document).scrollTop(jQuery('#gforms_confirmation_message').offset().top);jQuery(document).trigger('gform_confirmation_loaded', [6]);}, 50);}else{jQuery('#gform_6').append(contents);if(window['gformRedirect']) {gformRedirect();}}jQuery(document).trigger('gform_post_render', [6, current_page]);} );} );</script><script type='text/javascript'> jQuery(document).ready(function(){jQuery(document).trigger('gform_post_render', [6, 1]) } ); </script>
The problem:
1) I'm not sure how to dynamically set the input name and id so that they are sequential as you go down the form. Currently, as the code is set up, I'll only receive the submitted value of the first input no matter how many inputs are filled in.
I appreciate any help you can provide. Thanks!