Perhaps maybe I can’t. After thinking about it, the JS is browser side, and no way for the PHP to grab the value before submitting and being sent to the next page.
What I need to do is count the number of times it is clicked, and pass that value along with form values to the next page for PHP processing.
Thanks Jake. That did the trick. Perhaps you can help me some with the next step.
First let me give a very quick overview. I have a form where the “customer” is ordering photo shoots. What we did above was count the number of shoots they are ordering. That number gets passed to the email script where I need to email the results of the form.
What I am having trouble with is I need to only email the results, and not have empty data. On the form page, there are just 30 forms hidden in a div, and each time they click the “Add” button, it just shows the next form. So really 30 forms worth of data are sent.
What I am trying to do is tell the email script how many of the fields are filled out. The fields follow the logic of cap number plus field name. So a data set might look like:
1field1
1field2
1field3
2field1
2field2
2field3
3field1
3field2
3field3
and so on.
The problem of course is that this will contain 30 sets, but with a lot of empty ones. So how can I use that number I obtained from your script and only email the ones that have data? I am using the following email code:
<?php
//Grab values from form
$var= $_POST['Name']; //repeat for all form fields
//Email values
if (@mail("email@email.com", "Headwear Photography Request Form",
"A request form has been submitted with the following information:
Data set 1
Data set 2
Date set 3
repeat for all data sets filled out"
,"From: email@email.com")
) {
echo('Success messge');
} else {
echo('Fail message');
} ;
?>
Just to clarify, there arent’ 30 forms. There is one form with 30 data sets repeated. Each is in a hidden div and the next is shown when the button is clicked.
That makes sense. I know basic PHP, and don’t use it much. But when shown I can usually run with it.
So how do I get my email to use that array? Wouldn’t I need some sort of while loop? Not sure how to make that work with that email script. I don’t want separate emails for each data set, only 1 email with all data. That is my hang up now.
Yep. Well, saying that the ‘description’ field is mandatory (the script would check if it exists - if it doesn’t it will not bother with the rest of the form. If it has a chance of not being filled in, change it to a mandatory field).:
<?php
$mand_field = "description";
$field_list = array("description","ffull","f34left","f34right","f58left","f58right","fsideleft","fsideright","bfull","b34left","b34right","b58left","b58right","bunderstraight","bunderleft","bunderright","cfront","cside","cback","cvsr","background","notes");
$msgout = "";
for($i = 1; $i <= 30; $i++){
if(isset($_POST[$i.'description'])){
$msgout .= "<br /><br /><br />Form ".$i;
foreach($field_list as $field){
$msgout .= "<br />".$field.": ".$_POST[$i.$field];
}
}
}
if (@mail("email@email.com", "Headwear Photography Request Form",
"A request form has been submitted with the following information:
".$msgout,"From: email@email.com")
){
echo('Success messge');
}else{
echo('Fail message');
}
?>
Looks as though you may have based it off the fields I gave you being individually named. I had changed all the fields to arrays. But I am going to change back and see if it works.