Jump to content

PHP Validation / Conditional Statement


phpfreaknot

Recommended Posts

Hello,

 

I am trying to have users select multiple options from a dropdown list.  But before each selection, I would like to have a message appear on the screen asking if the user if they would like to select another option - Yes or No.

 

Yes or No would be required fields.  If the user select Yes, they can select another option from the drop down list (displaying all selected options on the screen before processing).

 

If the user select No, they can proceed to the next fields.

 

I have to searched the Internet for days, but was unable to locate anything close.  If possible I would like to implement the amselect.js code into this difficult task.

 

Can you guys please assist or point me in the right direction?

 

Link to comment
Share on other sites

I agree.

 

But unfortunately, the site's owner is requesting this feature. 

 

Basically, they are requesting

 

* A  multi select dropdown list

* This list is a required field

* A sub required / validation - users are required to select yes or no (would you like to select another option) before moving on.

 

I was able to create the multi select dropdown list using already created code - http://code.google.com/p/jquery-asmselect/

 

But I'm unable to figure out how to add the sub validation - yes or no.

Link to comment
Share on other sites

Hello,

 

I am trying to have users select multiple options from a dropdown list.  But before each selection, I would like to have a message appear on the screen asking if the user if they would like to select another option - Yes or No.

 

Yes or No would be required fields.  If the user select Yes, they can select another option from the drop down list (displaying all selected options on the screen before processing).

 

If the user select No, they can proceed to the next fields.

 

I have to searched the Internet for days, but was unable to locate anything close.  If possible I would like to implement the amselect.js code into this difficult task.

 

Can you guys please assist or point me in the right direction?

 

I would NOT use javascript for any crucial stuff, only for fancyness. So real validation must be done by php, but you can add extra validation to alert the user that the value is not as expected or something, but certainly don't rely on it.

Why not build the menu on the fly? or was that what you were already meaning?

Small question are the options stored in a database or hardcoded in some array.

If you could give an example of what you want i might be able to help a bit.

Link to comment
Share on other sites

Please review the attached screen print and code.

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<link rel="stylesheet" href="css/lytebox.css" type="text/css" media="screen">
<link rel=Stylesheet type="text/css" media=all href="SpryValidationSelect.css">


	<link rel="stylesheet" type="text/css" href="jquery-ui.css">
<link rel=Stylesheet type="text/css" media=all href="css/SpryValidationRadio.css">

        <link rel="stylesheet" type="text/css" href="style.css">

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
	<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script

                        <script type="text/javascript" src="jquery.js"></script>
                         <script type="text/javascript" src="js/SpryValidationRadio.js"></script>

    <script type="text/javascript" src="js/jquery.asmselect.js"></script>
      <script type="text/javascript" src="SpryValidationRadio.js></script>


    
    
    
	<script type="text/javascript">
	$(function() {

		$('#firstname').val("");
                        $('#lastname').val("");
                        $('#email').val("");
                        $('#phone').val("");

		$("#ahmID").autocomplete({
			source: "dbConnection.php",
			minLength: 2,
			select: function(event, ui) {
				$('#ahmID_id').val(ui.item.id);
				$('#firstname').val(ui.item.firstname);
                                        $('#lastname').val(ui.item.lastname);
                                        $('#email').val(ui.item.email);
                                        $('#phone').val(ui.item.phone);
			}
		});


	});



	</script>

<script type="text/javascript">
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function prepareInputsForHints() {
var inputs = document.getElementsByTagName("input");
for (var i=0; i<inputs.length; i++){
	// test to see if the hint span exists first
	if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
		// the span exists!  on focus, show the hint
		inputs[i].onfocus = function () {
			this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
		}
		// when the cursor moves away from the field, hide the hint
		inputs[i].onblur = function () {
			this.parentNode.getElementsByTagName("span")[0].style.display = "none";
		}
	}
}
// repeat the same tests as above for selects
var selects = document.getElementsByTagName("select");
for (var k=0; k<selects.length; k++){
	if (selects[k].parentNode.getElementsByTagName("span")[0]) {
		selects[k].onfocus = function () {
			this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
		}
		selects[k].onblur = function () {
			this.parentNode.getElementsByTagName("span")[0].style.display = "none";
		}
	}
}
}
addLoadEvent(prepareInputsForHints);
</script>

</head>
<body>
<script type="text/javascript">
	$(document).ready(function() {

		$("#cities").asmSelect({
			animate: true,
			highlight: true,
			sortable: true
		});

		$("#add_city_btn").click(function() {

			var city = $("#add_city").val();
			var $option = $("<option></option>").text(city).attr("selected", true);

			$("#cities").append($option).change();
			$("#add_city").val('');

			return false;
		});

	});

</script>




<div id="paperHolder">
    <div id="paperTop">
        <img src="images/pp_topright.png" class="fr" width="13" height="13" alt=""><img src="images/pp_topleft.png" class="fl" width="13" height="13" alt=""><div id="topshadow"></div>
    </div>
    <div id="paperLeft"><div id="paperRight">
        <div id="allContent">

<!-- Main Menu -->
	<div class="headerHolder">
        <div id="up_greenblock" class="ishome">
			<h1>New Hire Request Form</h1>


    	    </div>
        <div id="abs"><!-- H.Shadow --></div>
	</div>


        <ul id="menu">
		<li class="menuActiveGreen" ><a href="index.php">New Hire</a></li>
		<li><a href="index2.php">Shared Folder Access</a></li>

	  </ul>

<div class="ffx" style="height: 20px;"></div>


<div class="ffx"></div>

      <div class="content">

<div align="center">
        <div id="signupForm">
            
<form action="#"  method="post" id="contactform">
    
<fieldset><legend><span>1</span> Requestor Details</legend>
<br>
<p class="ui-widget">
        <dl>
            <dt>
        <label for="ahmID"><span class="red">*</span> Employee ID: </label>
            </dt>
            	<dd>
<input type="text" id="ahmID"  name="ahmID" class="text1" /><span class="hint">ID begins with an A or N.  Employee ID will autopopulate your information.<span class="hint-pointer"> </span></span> <br/>
        </dd>
        <dt><label for="firstname">First Name: </label></dt>
        <dd>
        <input readonly="readonly" type="text" id="firstname" name="firstname" class="text" />	<span class="hint">This field is ReadOnly.<span class="hint-pointer"> </span></span>
</dd><br/>
        <dt><label for="lastname">Last Name: </label></dt>
        <dd>
        <input readonly="readonly" type="text" id="lastname" name="lastname" class="text" /><span class="hint">This field is ReadOnly.<span class="hint-pointer"> </span></span><br/>
        </dd>
        <dt><label for="email">E-Mail: </label></dt>
        <dd>
         <input readonly="readonly" type="text" id="email" name="email" class="text" /><span class="hint">This field is ReadOnly.<span class="hint-pointer"> </span></span><br/>
        </dd>
        <dt><label for="phone">Phone: </label></dt>
        <dd><input readonly="readonly" type="text" id="phone" name="phone" class="text" /><span class="hint">This field is ReadOnly.<span class="hint-pointer"> </span></span><br/>
        </dd>

        </dl>
</p>
</fieldset>


<fieldset><legend><span>2</span> Access to Shared Network Folder(s)</legend>
<br>
<table width="100%" cellpadding="0" cellspacing="0" id="userDetails">
<tr id="tr_userfullname"><td>
<span id="acceptContainer1">
  <label for="decline">
  <input type="radio" name="accept" id="decline" value="decline" checked="checked"/>
  Yes</label>
  <label for="accept">
  <input type="radio" name="accept" id="accept" value="accept"/>
  No</label>
  <span class="radioInvalidMsg">Please select Yes or No for in the Shared Folder access section</span> </span><br />

<script type="text/javascript"> 
<!--
var acceptContainer1 = new Spry.Widget.ValidationRadio("acceptContainer1", {invalidValue:"decline", validateOn:["change"]});
//-->
</script>


</tr></td>
</table>

<?php
$dir    = '//domainname/department_shares';
$files1  = array_diff(scandir($dir), array('.', '..'));
$files1 = str_replace(" ", " ", $files1);

echo '<br />';
echo '<SELECT multiple="multiple" id="cities" name="cities[]" title="Click to Select Folder">';
foreach ($files1 as $key => $value)
{

echo '<OPTION value='.$value.'> '.$value.'';

}

echo '</select>';

?> 
  <input type="submit" name="submit4" id="submit4" value="Submit" />
</table>
</fieldset>

</form>
</div>
        </div>


        </div>
    </div></div>


</div></div>

</body>
</html>

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.