Jump to content

Hidden Fields Validation


ainoy31

Recommended Posts

Yeah.  I tried what you have stated and it does not seem to work.

 

Here are the hidden fields.


$skipCovCheckPage = "/customers/sales/productGroups.php?customer_id=12"
<form name="dataForm" method="POST" action="<?php echo $skipCovCheckPage; ?>">
<input type="hidden" name="city" value="<?=$data['city'];?>">
<input type="hidden" name="state" value="<?=$data['state'];?>">
<input type="hidden" name="zip_code"  value="<?=$data['zip_code'];?>">
<input type="hidden" name="phone_1" value="<?=$data['phone_1'];?>">
<input type="hidden" name="region_id" value="<?=$data['region_id'];?>">
<input type="hidden" name="saleType" value="<?=$data['saleType'];?>">

<div class="ButtonContainer"> 
<a class="Button Primary" href="#" id="FormSubmit" onClick="return validateService();"><span>Continue</span></a>
</div>
</form>

 

The javascript:

function validateService()
{
if(document.dataForm.elements['address_1'].value == "")
{
alert("Street Name is invalid.");
return false;
}
if(document.dataForm.elements['city'].value == "")
{
alert("City is invalid.");
return false;
}
if(document.dataForm.elements['state'].value == "")
{
alert("State is invalid.");
return false;
}
if(document.dataForm.elements['zip_code'].value == "")
{
alert("Postal Code is invalid.");
return false;
}
if(document.dataForm.elements['phone_1'].value == "")
{
alert("Phone 1 is invalid.");
return false;
}
document.dataForm.action = '<?php echo $skipCovCheckPage; ?>';
document.dataForm.submit();
}

 

The alert message will popup even though the street name field is populated.  Much appreciation. AM

 

 

Link to comment
Share on other sites

its working for me with this test code

 

 

<script>
function CheckForm()
{
if(document.getElementById('CM').value=='')
{
	alert('THERE IS NO VALUE');
}
else
{
	alert("The Value of the input is "+ document.getElementById('CM').value);
}
}
</script>



<form action='' method='post'>

<input type='hidden' value='CrackerMonkey' name='CM' id='CM' />


<input type='submit' value='submit' onmousedown='CheckForm();' />
</form>

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.