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:
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>
Hi jstratos,
Something like
Bob
Something like
<?php
$code =& JRequest::getString('login_name', '', 'post');
if ( $code != 'the correct code' ) {
return "sorry this is not the correct code";
}
?>
Bob
Thanks Bob! Just saw this post today... guess I forgot to check off "Notify me".
I'll test this code.🙂
I'll test this code.🙂
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?
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";
}
?>
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
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
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:
'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.