View Full Version : Adding Checkboxes to Form
jurinski334466
05-07-2009, 04:54 PM
Is it possible to add fields containing checkboxes to the Contact Form when using the Contact Form Solution Pack? I would like the user to be able to select one or many courses from a list and have the choices submitted in the email along with the usual contact information.
Example:
Please select course button, complete the form, and submit below:
(box#1) Course #1
(box#2) Course #2
(box#3) Course #3
The standard contact form works fine without the boxes, but I cannot get the form working after I add the additional checkbox fields. I am not sure what changes I need to make to get the form working. Does additional php need to be added in the form fields or to other files? Do the boxes need to be validated in order for the form to work?
As long as I'm asking for the moon, is it also possible to have the form validate the fields to check whether at least one of the checkboxes has been selected? I would greatly appreciate any help and advice that you can spare to get this form going. Thank you.
jurinski334466
05-08-2009, 03:10 PM
This post is a continuation of my previous post asking about Adding Checkboxes to a form.
After trying to set the email settings and validate the Contact Form I have a similar problem to the question posted on 3/19/09 "red exclamation mark in server behaviors":
"According to the documentation you are able to use Universal Email to further customize the Contact Form. When I go to the server behaviors for the page there is a red exclamation mark by Universal Email(Mail for Linux). When I go to customize the page all the settings are lost and a new Universal email folder is created in the root. Why is this doing this and how do I customize the page that is in the solution pack without losing what is there?"
The solution for that thread was to update the UniversalEmail/EmailTemplates file or find and replace:
Mail_for_Linux_PHP
with
mail_PHP
and replace:
Mail for Linux
with
mail
I did a find and replace for these terms and came up with no instances of these terms in my site to correct. However, I do have double files of everything.
I am using the current version (1.0.2) of the Contact Form Solution Pack on a mac running OS X 10.5.6. I also have Universal Email and the Validation Toolkit installed. When editing the Contact Form, I also end up with two folders for Universal Email and the Validation Toolkit. Editing the Contact Form using the server behavior panel in Dreamweaver CS3 creates edits in the root files and not to the Contact Form files. The Contact Form then appears to be trying to read off of files in both locations which might be causing the errors I am experiencing. If I delete the files in root, the folders and files are recreated in root when I next try to edited the form's server behaviors and make corrections.
Also, I tried following the advice for validating dropdown list menus in the thread on 3/04/09 "I need some help with validation." I tried using the suggested code of
<option value="" selected="selected">Auswahl</option> using
<option value="" selected="selected">Choose</option> and
$WAFV_Errors .= WAValidateRQ(((isset($_POST["Title"]))?$_POST["Title"]:"") . "",true,8);
instead.
DW has problems validating the code saying: ""selected" is not a valid value for the "selected" attribute in any of the currently active versions."
What is a valid value in this situation?
I apologize for my inexperience and the length of these posts, but I'm not sure how to untangle the errors in the form. Does anyone have suggestions or tips how to fix whatever it is that I am doing wrong? Thank you.
Ray Borduin
05-11-2009, 07:52 AM
<option value="" selected="selected">
should just be:
<option value="" selected>
jurinski334466
05-12-2009, 06:58 PM
Thank you for the answer to the select question. That part works now. Hooray! I'm trying to convert a preexisting form and am in new territory...
Could you please help clear up my confusion about validating new fields, VTK, & UE?
1. The DW bindings panel lists WA Validated Entries including new fields. Does this mean that the Contact Form already performs some type of validation on newly added fields? I'm trying to decide what server and/or client validation the new fields need, and I can't tell what is already being done.
2. When I open WA Server Validations and Universal Email from the DW server behavior panel and make changes, DW/WA creates new Validation Tool Kit and Universal Email folders and files outside the Contract Form Solution folder. Adding VTK client validation also does this.
Is this how the contact form is supposed to work when you make changes or additions to the form?
When I started the project, I renamed the CFS folder and contactus.php file in DW.
Is renaming causing the problem with the file and folder duplication?
I have not had any success with removing, renaming, or combining the VTK or UE folders and files, and have not found any other relevant posts that deal with the issue. Clicking on the red exclamation point and reconfiguring the input produces new files with code that differs from code in the original CFS code, and having all four files produces code that I cannot get to work. This is a problem because I can't make additions or changes without "breaking" the form.
How do I fix this?
Thank you for a reply!
Ray Borduin
05-13-2009, 07:33 AM
All of the files should be added to the root directory of the web site. The problem is that you have moved them into the contact form solution folder. You should really only move the .php page itself to a sub-folder if necessary and leave all of the folders in the root to work properly in DW templates and server behavior tonot have exclamation points.
jurinski334466
05-15-2009, 02:57 PM
Thanks, Ray. Mired in the details of converting an old form, I couldn't see the obvious. The form functions now except for problems with checkbox validation.
In defense of my blunder, the Contact Form did not come with any specific instructions about how & where to install all the files. Absent WA directions, I followed the instructions in the "Simple Steps to Contact Form Solution Pack and Dreamweaver" posting in the old Forum Archive and some other posts and came to the wrong conclusions.
It would be very helpful if WA products could include basic installation information with each product and with each download. New, infrequent, and forgetful users could start using your products with confidence, while more experienced users could ignore the info. For the inexperienced, it's the difference between "Oh crud! Where do all these files go and what do I do now?" and "Great! Let's get started!"
Back to validating the checkboxes:
1. Is there a way to use the VTK or Spry to stop the form from submitting if one of the check boxes has not been checked?
I tried to expand the Spry Checkbox validation around the checkbox group but that did not work. (Perhaps because the Spry <span> tag would have to surround block-level elements?)
2. Or if the WA tools can't be configured to work, do I need to create some sort of php array to check the boxes? If I do, where do I insert the code to integrate with the CF code? On the form itself or somewhere else?
3. Is there a way to make the checkboxes sticky? I have tried adding the WA Validated Entries to the checkbox code, but the information is lost if another error causes the page to reload.
<td colspan="2" class="bluexxs"><label>
<input name="course1" type="checkbox" id="course1" value="<?php echo(ValidatedField("regis","course1")) ?>" />
</label>
p.m. </td>
I would appreciate any advice you have or can point me to so I can get this form working. Thanks again for your advice and help.
Ray Borduin
05-18-2009, 06:27 AM
1) Yes, VTK and spry can be used. Do you have a sample page where you tried adding spry and it didn't work? I could try to debug that.
2) They can be.
3) If you use the dynamic button of the checkbox it will have an option for checking. Usually the value would be the course number, not the validated field value. The validated field value should be used for the dynamic value to check the box associated with that value. So it looks like your checkbox is set up wrong. Update the value to be the course number and use the dynamic button in the properties panel to select the previously validated value.
jurinski334466
05-20-2009, 06:30 AM
Hi Ray,
Thanks yet again. You have been very helpful. Progress is being made. When things don't work, I fall back on shifting code around hoping to hit on something that does work with mixed results.
1. The checkboxes are now sticky. Per your suggestion, this is the code that worked:
Checkbox Field code:
<tr>
<td colspan="2" class="bluexxs">
<label>
<input <?php if (!(strcmp((ValidatedField("regis","course1")),"course1"))) {echo "checked=\"checked\"";} ?> <?php echo(ValidatedField("regis","course1")) ?> name="course1" type="checkbox" id="course1" value="course1" />
</label>
</td>
However, I'm getting confused in the all the details. Do I need both php statements?
I would really appreciate help debugging the page. Is there a way to privately send you the link?
Even more Questions....
2. Email Field Question:
I used the email field and code from the WA contact form field. It does not seem to be set up to allow uppercase entrys; i.e. "MYNAME@THIS.COM" Validation balks at the ".COM" Is this the way the email validation works or is it the result of some screwball changes I made? What change where, do I need to make to create a more forgiving validation? I don't want someone to have to go back and reenter the email info just because they left the caps lock on. Or am I missing something?
Email Field code:
<tr>
<td colspan="4"><div align="right" class="formtext"><span class="star">*</span>Your
E-mail:</div></td>
<td colspan="3"><span id="sprytextfield2">
<label>
<input name="Email_Address" type="text" class="inputValue" id="Email_Address" onblur="if (document.getElementById('emailServerError')) document.getElementById('emailServerError').style. display='none'" value="<?php echo(ValidatedField("regis","Email_Address")) ?>" size="25" maxlength="35"/>
</label>
</span> </td>
<td colspan="7"><span class="textfieldRequiredMsg"><span class="error_message2">Please enter a valid email.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
<?php
if (ValidatedField("regis","regis")) {
if ((strpos((",".ValidatedField("regis","regis").","), "," . "2" . ",") !== false || "2" == "")) {
if (!(false)) {
?>
<span id="emailServerError" class="textfieldServerError"><span class="error_message2">Please enter your email address so we<br />
may confirm your registration.</span></span>
<?php //WAFV_Conditional regis.php regis(2:)
}
}
}?></td>
</tr>
3. Phone Field Question:
I added a spry formatting hint to the Phone text field which is not a required field. Is there a way to prevent the hint text from submitting?
Phone Field code:
<tr>
<td colspan="4"><div align="right" class="formtext">Phone #:</div></td>
<td colspan="3"><span id="sprytextfield5">
<label>
<input name="Phone" type="text" class="inputValue" id="Phone" value="555-555-5555" onFocus="if(this.value=='555-555-5555')this.value='<?php echo(ValidatedField("regis","Phone")) ?>" size="12" maxlength="12" />
<span class="textfieldInvalidFormatMsg"><span class="error_message2">Example: 123-456-7890.</span></span></label>
</span></td>
<td colspan="6"><span class="textfieldInvalidFormatMsg"><span class="error_message2">Enter phone number as 555-555-5555.</span></span>
<?php
if (ValidatedField("regis","regis")) {
if ((strpos((",".ValidatedField("regis","regis").","), "," . "8" . ",") !== false || "8" == "")) {
if (!(false)) {
?>
<span class="error_message2">Enter phone number as 555-555-5555.</span>
<?php //WAFV_Conditional regis.php regis(8:)
}
}
}?></td>
</tr>
4. Non-Required Fields:
The address fields are not required and can be submitted blank. I followed the example of the contact and email fields. The code works and the information passes to the email, but I'm unsure whether it's the correct way to do it. Should the target value for the "value=" be the php ValidatedField value?
Address field code:
<tr>
<td colspan="4"><div align="right" class="formtext">Address #1:</div></td>
<td colspan="3"><label>
<input name="Address1" type="text" class="inputValue" id="Address1" value="<?php echo(ValidatedField("regis","Address1")) ?>" size="25" maxlength="50" />
</label> </td>
<td colspan="7"> </td>
</tr>
5. I also still have my checkbox validation question still on the horizon but am trying to get the rest of the form in order before facing into that one. Thank you again for following up on all my long-winded questions and helping me sort out my confusion.
jurinski334466
05-20-2009, 06:51 AM
Sorry. There's probably a way to get the smilies out of the posted code but it's not readily apparent...
Ray Borduin
05-20-2009, 07:36 AM
1) <?php echo(ValidatedField("regis","course1")) ?> is not needed and can be removed
2) you could convert the email to lower case when you validate.
3) I'm not sure I haven't played with this option in spry... i imagine there is a way
4) Yes, it should still have the validated field default so that it will maintain its value after failed validation
5) Good luck
crazysuzy
05-23-2009, 04:57 PM
I am running into a problem making my radio group entries stick. I have several radio groups on my form, all of which are optional. Everything on my form sticks when validation fails, except for the radio groups.
I have tried the following for a radio group named Sommelier_Queen:
<input <?php if (!(strcmp(((isset($_POST["Sommelier_Queen"]))?$_POST["Sommelier_Queen"]:""),"Cab_Double"))) {echo "checked=\"checked\"";} ?> type="radio" name="Sommelier_Queen" value="Cab_Double" id="sommelierQueen_0" />
And:
<input <?php if (!(strcmp((ValidatedField("register2","Sommelier_Queen")),"Cab_Double"))) {echo "checked=\"checked\"";} ?> type="radio" name="Sommelier_Queen" value="Cab_Double" id="sommelierQueen_0" />
I have also tried replacing the first "Sommelier_Queen (after register2) with "Cab_Double", which also didn't work. And I put spry radio group validation in place with no results. Not sure what else to try. Any help would be appreciated.
Thank you.
Ray Borduin
05-26-2009, 09:32 AM
It should work with:
<input <?php if (!(strcmp((ValidatedField("register2","Sommelier_Queen")),"Cab_Double"))) {echo "checked=\"checked\"";} ?> type="radio" name="Sommelier_Queen" value="Cab_Double" id="sommelierQueen_0" />
Ray Borduin
05-26-2009, 09:33 AM
Does it add "Checked" for any of the radios when you view the source code? Do you have a sample url? Are you adding the code manualy or using the dynamic button in dreamweaver?
crazysuzy
05-26-2009, 12:16 PM
Thanks for the fast response Ray. I tried the code that you suggested and it made no difference. Here is the link to the live page:
http://firstcrushwinemaking.com/register2.php
Ultimately I would like to use Spry validation to ensure that at least one package is selected on the page by setting all of them up in one radio group. I experimented with it all day yesterday though and it breaks the form by making it so that nothing is sticky after that AND the spry validation error doesn't appear at all. Guess I'm in over my head.
Thanks for your help.
Ray Borduin
05-26-2009, 12:38 PM
Spry should work. In fact we use spry and webassist server validations for validation in the most recent version of our solutions. Spry is all javascript and works before the page submits and webassist server code deals with the submitted form... they shouldn't be able to step on eachother.
In terms of radio... what about if you try:<input <?php if (ValidatedField("register2","Sommelier_Queen")=="Cab_Double") {echo "checked";} ?> type="radio" name="Sommelier_Queen" value="Cab_Double" id="sommelierQueen_0" />
crazysuzy
05-26-2009, 12:59 PM
No, that didn't work either. See it here (the first package only has the new code):
http://firstcrushwinemaking.com/register3.php
Ray Borduin
05-26-2009, 01:13 PM
Could be a typo... I can't see the code and debug by seeing the resulting page. I can only confirm that it doesn't work.
What happens if you use:
<?php echo(ValidatedField("register2","Sommelier_Queen")); ?>
<input <?php if (ValidatedField("register2","Sommelier_Queen") == "Cab_Double") {echo "checked";} ?> type="radio" name="Sommelier_Queen" value="Cab_Double" id="sommelierQueen_0" />
does that write the value of the submitted radio button before the radio? At least that might narrow down the problem... also I see your page is now register3... if you are changing page names I wonder if page references are getting out of synch... notice the examples I gave still have "register2" as the page name.
Maybe you should upload the whole page in context. Radio buttons work exactly like everything else, so if it isn't working there is a typo and nothing inherently wrong with using radios.
crazysuzy
05-26-2009, 01:24 PM
Ray - Now that you mentioned how changing file names could be a problem, I realized that my checkboxes were validating with a different FORM NAME than the rest of them. The code that I used from Web Assist uses 'contact' for the form name, not register2 (or register3). I fixed it and the checkboxes are sticky just as they should be.
Thanks for the time on this. Maybe now my Spry validation for all of the checkboxes on the page will work too.
Ray Borduin
05-26-2009, 01:26 PM
crazy suzy ;)
vBulletin® v3.8.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.