Adding Reference Code field

jstratos 03 Nov, 2009
I wanted to add a form field where the input would be matched to a predetermined code - similar to a coupon code where the input would be compared to the parent code. If it didn't match then the form would not be processed... "sorry this is not the correct code".

Is there a server side validation code to configure this?

Input code on the form would be:
<div class="form_item">
  <div class="form_element cf_textarea">
    <label class="cf_label" style="width: 150px;">Enter Authorization Code</label>
    <input type="text" name="login_name" id="auth_code">
  </div>
  <div class="cfclear"> </div>
</div>
GreyHead 03 Nov, 2009
Hi jstratos,

Something like
<?php
$code =& JRequest::getString('login_name', '', 'post');
if ( $code != 'the correct code' ) {
  return "sorry this is not the correct code";
}
?>

Bob
jstratos 27 Feb, 2010
Thanks Bob! Just saw this post today... guess I forgot to check off "Notify me".
I'll test this code.🙂
jstratos 27 Feb, 2010
Bob -
The form code needs tweaking because it's not delivering the "return" statement? If I enter anything other than the code "12345", the form just refreshes without displaying the error message or it's not pausing or stopping long enough to read it. When the correct code is entered, it redirects correctly. Any thoughts?


<div class="form_item">
  <div class="form_element cf_textarea">
    <label class="cf_label" style="width: 150px;">Enter Authorization Code</label>
    <input type="text" name="login_name" id="auth_code">
    <input type="submit" name="Submit" id="Submit" value="Submit" />
  </div>
  <div class="cfclear"></div>
</div>

<?php
$code =& JRequest::getString('login_name', '', 'post');
if ( $code != '12345' ) {
  return "sorry this is not the correct code";
}
?>
GreyHead 27 Feb, 2010
Hi jstratos,

Well, if you are using a redirect that sounds like the correct behaviour for a normal submission; not sure why it doesn't just redisplay the form on an error though. Please test without the redirect and see what happens then.


Bob
jstratos 27 Feb, 2010
Same thing?

'RETURN' by-passes error statement altogether and refreshes the page. When a correct code is entered the second "echo" saying, "the entry is correct" works.

Here's my test with echo statement:


<div class="form_item">
  <div class="form_element cf_textarea">
    <label class="cf_label" style="width: 150px;">Enter Authorization Code</label>
    <input type="text" name="login_name" id="auth_code">
    <input value="submit" name="Submit" id="Submit" type="Submit" />
  </div>
 <div> </div>
</div>
<?php
$code =& JRequest::getString('login_name', '', 'post'); 
if ( $code != '12345' ) {
   return "sorry this is not the correct code"; //RETURN HERE REFRESHES PAGE ONLY
}
else {
   echo "The code is correct"; //THIS WORKS ON A CORRECT ENTRY
}
?>
This topic is locked and no more replies can be posted.