Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

make 2 checkboxes mandatory before submit to pay

Hello,

I have a form with some fields and a drop down for price. The price chosen is passed through to paypal when the form is submitted.

I have 2 checkboxes I need to be checked before this can be submitted, one for being over 21 and one for having read terms and conditions. I also need one or more of the regular text fields to be filled.

Below I have stripped out all the other form elements and left just the stuff concerning this question.

What is the best way to make sure the field below and both checkboxes are checked before the submit being allowed?

Thank you :)
<form action="https://www.paypal.com/cgi-bin/webscr" NAME="FORM" method="post">
          <input type="hidden" name="cmd" value="_s-xclick" />
          <input type="hidden" name="hosted_button_id" value="" />
          
          
             
               
         <div>
         <input type="hidden" name="on2" value="Car Registration" />
                <label for="Registration">Car Registration</label></td>
       
                <input name="os2" type="text" size="42" maxlength="200" />
             
          
            </div>
            
            
      

        
			<p class="radioLabel">
                <input type="hidden" name="on6" value="Terms and Conditions" />
               <input name="os6" type="checkbox"/> I have read the <a href="terms.html">terms &amp; conditions</a> *<br />
               
              </p>
              

  
  

                
        		<p class="radioLabel">
                <input type="hidden" name="on7" value="Over 21" />
                <input name="os7" type="checkbox"/> I am over 21 years old *<br />
               
              </p>

           

  
  
          <p>
            <input type="hidden" name="currency_code" value="GBP" />
            </p>
          <p>&nbsp;</p>
          <p>
            <input type="image" src="images/click_to_pay.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online." />
            <img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1" /></p>
        </form>

Open in new window

0
igloobob
Asked:
igloobob
  • 4
  • 2
  • 2
  • +1
1 Solution
 
Ray PaseurCommented:
You must validate this information on the server side, after you have received the form input.  You can make up some kind of JavaScript "return FALSE" function for onSubmit.  Nice people will not bypass the JavaScript and post evil things into your script.  Hackers and 'bots will, however.  And you need to protect your data against that risk.
0
 
leakim971PluritechnicianCommented:
<form action="https://www.paypal.com/cgi-bin/webscr" NAME="FORM" method="post" onsubmit="return validate();">

function validate() {
   return document.getElementsByName("on6")[0].checked && document.getElementsByName("on7")[0].checked;
}

Open in new window

0
 
igloobobAuthor Commented:
Hello Ray

could you possibly point me in the direction of somewhere I might find a tutorial for this? What you have said above I have no idea how to do...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
igloobobAuthor Commented:
@leakim971,

thanks for the reply, I tried your suggestion, that stops the submit button working perfectly, I just need to add an error message of some sort now...
0
 
leakim971PluritechnicianCommented:
0
 
igloobobAuthor Commented:
that looks very 'tasty' indeed leakim971!

Thanks I will have a proper look into that tomorrow and report back for points etc,

I have to leave for the day now.
0
 
re-searcherCommented:
It's better you using 2-factor verification.

+ first one is using javascript for validation. read this article -> http://www.the-art-of-web.com/javascript/ajax-validate/
+ second one is using php validation (with codes which you will write)

if you doing these type of verification together, you will reduce request to server and you will be sure when you receive requests from visitors it pass some verification (if their browser support javascript).

i don't want just answer to questions, many time when users ask question and I ask question,too. we don't know best solution...
0
 
re-searcherCommented:
but if your choice is not ajax validation method, you solution is here:
<script type="text/javascript" language="JavaScript">
<!--
function checkform(theForm) {
	if (theForm.os6.checked == false || theForm.os7.checked == false) 
	{
		alert ('You should choose both checkboxes!');
		return false;
	} else { 	
		return true;
	}
}
//-->
</script> 
<form action="https://www.paypal.com/cgi-bin/webscr" NAME="FORM" method="post" onsubmit="return checkform(this);">
  <input type="hidden" name="cmd" value="_s-xclick" />
  <input type="hidden" name="hosted_button_id" value="" />
  <div>
    <input type="hidden" name="on2" id="on2" value="Car Registration" />
    <label for="Registration">Car Registration</label>
    </td>
    <input name="os2" id="os2" type="text" size="42" maxlength="200" />
  </div>
  <p class="radioLabel">
    <input type="hidden" name="on6" value="Terms and Conditions" />
    <input name="os6" id="os6" type="checkbox"/>
    I have read the <a href="terms.html">terms &amp; conditions</a> *<br />
  </p>
  <p class="radioLabel">
    <input type="hidden" name="on7" value="Over 21" />
    <input name="os7" id="os7" type="checkbox"/>
    I am over 21 years old *<br />
  </p>
  <p>
    <input type="hidden" name="currency_code" value="GBP" />
  </p>
  <p>&nbsp;</p>
  <p>
    <input type="image" src="images/click_to_pay.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online." />
    <img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1" /></p>
</form>

Open in new window

0
 
igloobobAuthor Commented:
we didn't use this in the end as my colleague had already sorted it with a javascript but this would have worked great.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now