Basic If Statement question
Moderator: General Moderators
Basic If Statement question
NOTE: I have re-submitted this problem in a new topic to include new advice / update code. For the latest, please refer to:
viewtopic.php?p=143976#143976
------------------------------------------------------------------------------
Hello all,
I am trying to create a form that uses php to validate it. NOTE: I want to avoid client-side languages. The validation I'm using works fine.
If the form is filled in correctly, feedbacksent.html loads. If the form is filled in incorrectly, I want the page to refresh showing errors (which it does) and then the browser to jump down to where the form is located (which is wear my problem lies...)
Please now scroll down to my posting on Saturday 13th, 7pm for my code and more details...
viewtopic.php?p=143976#143976
------------------------------------------------------------------------------
Hello all,
I am trying to create a form that uses php to validate it. NOTE: I want to avoid client-side languages. The validation I'm using works fine.
If the form is filled in correctly, feedbacksent.html loads. If the form is filled in incorrectly, I want the page to refresh showing errors (which it does) and then the browser to jump down to where the form is located (which is wear my problem lies...)
Please now scroll down to my posting on Saturday 13th, 7pm for my code and more details...
Last edited by dave79 on Fri Nov 19, 2004 7:28 am, edited 3 times in total.
1- You shold specify the full URL $location="http://yoursite........
2-You can scroll down with javascript.. it was something like document.scoll() or something look it up on google
2-You can scroll down with javascript.. it was something like document.scoll() or something look it up on google
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
I've tried using your solution but the code below does not work. Can anyone spot a problem? It works up to the line:
header ("Location:$location");
header ("Location:$location");
Code: Select all
<?php }
if (isset($HTTP_POST_VARSї"submit"]) and ($checked)){
$msg .= "Firstname: ".$HTTP_POST_VARSї"firstname"]."\n";
$msg .= "Lastname: ".$HTTP_POST_VARSї"lastname"]."\n";
$msg .= "Company: ".$HTTP_POST_VARSї"company"]."\n";
$msg .= "website: ".$HTTP_POST_VARSї"website"]."\n";
mail("info@mywebsite.com","Client Portfolio request for references", $msg);
$location = "http://mywebsite.com/feedbacksent.html";
header ("Location:$location");
}
else {
header ("Location:client_portfolio_form_with_template.php#form");
}
?>Thanks for the response. I've tried your suggestion but that doesn't solve it. I've just found out I've been getting the following message (which was hidden behind some graphics):
Warning: Cannot modify header information - headers already sent by (output started at /mywebsite.com/user/htdocs/testarea/client_portfolio_form_with_template.php:59) in /home/fhlinux196/n/mywebsite.com/user/htdocs/testarea/client_portfolio_form_with_template.php on line 623
Note: my php file follows the format:
1. Defining rules/validation
2. HTML
3. Code shown in this posting
Is there anything I can use in replace of 'header'? The code works if 'header' is only used once, but not if used twice. Is there anything I can use instead?
Warning: Cannot modify header information - headers already sent by (output started at /mywebsite.com/user/htdocs/testarea/client_portfolio_form_with_template.php:59) in /home/fhlinux196/n/mywebsite.com/user/htdocs/testarea/client_portfolio_form_with_template.php on line 623
Note: my php file follows the format:
1. Defining rules/validation
2. HTML
3. Code shown in this posting
Is there anything I can use in replace of 'header'? The code works if 'header' is only used once, but not if used twice. Is there anything I can use instead?
Thanks to all who have contributed. Still having problems though. My script below has ob_start in it now. (see below for problems):
The script works fine if I remove the following lines. With them, the script doesn't even load (i.e. no error message!). However, without them, the browser doesn't jump down the form:
I know the concept *can* work because I've tested making the browser jump to the form when the form is filled in corrently (i.e. currently on passing form validation, the feedbacksent.html is loaded - I've tested the concept by replacing this file with #form and the browser does jump to the form).
It would be great to sort this out. When it is sorted, i'll post the full script. You can test the script/form (without the second "else {..."), here:
http://www.testarea.north-square.com/fo ... mplate.php
...feel free to fill it in/fail validation etc.
Weirdan | Dave, please use
Code: Select all
<?php
ob_start();
function check_len(&$check, $field, $max, &$err_field, $err="", $min,
// etc, more statements here that determine validation (which work well)
if (empty($HTTP_POST_VARS["firstname"])) $HTTP_POST_VARS["firstname"]="";if (empty($err_firstname)) $err_firstname=" ";
// More statements here, 1 for each field in the form
$checked = true; if (isset($HTTP_POST_VARS["submit"])){
check_len($checked, $HTTP_POST_VARS["firstname"],50,$err_firstname,"Your first name cannot exceed 50 characters",1,"You must fill in your first name");
// More statements here, 1 for each field in the form
}
if ( empty($HTTP_POST_VARS["submit"]) or (!$checked) ){
<!-- my HTML goes here. Including my form with id="form" -->
<?php }
if (isset($HTTP_POST_VARS["submit"]) and ($checked)){
$msg .= "Firstname: ".$HTTP_POST_VARS["firstname"]."\n";
// More statements here, 1 for each field in the form
mail("info@mywebsite.com","Email subject goes here", $msg);
$location = "http://www.mywebsite/feedbacksent.html";
header ("Location:$location");
}
else {
$failvalidation = "http://www.mywebsite/this_script.php#form";
header ("Location:$failvalidation");
}
ob_end_flush();
?>Code: Select all
else {
$failvalidation = "http://www.mywebsite/this_script.php#form";
header ("Location:$failvalidation");
}It would be great to sort this out. When it is sorted, i'll post the full script. You can test the script/form (without the second "else {..."), here:
http://www.testarea.north-square.com/fo ... mplate.php
...feel free to fill it in/fail validation etc.
Weirdan | Dave, please use
Code: Select all
tags to post php code. [/color]I know it can be done using php, because I've created this example. Here, instead of a correctly completed form taking the user to the "formsent.html", it jumps users back up to the form. I suggest you test this by filling in the form (don't press submit yet), and then scrolling so that the "request references" button is right at the top of the screen and then pressing it.
http://www.testarea.north-square.com/fo ... d_test.php
This proves that my problem relates to my IF statement, rather than anything else. I would be most grateful if someone could read through the logic and tell me how I can make the screen jump up to the form, when a user fails validation.
http://www.testarea.north-square.com/fo ... d_test.php
This proves that my problem relates to my IF statement, rather than anything else. I would be most grateful if someone could read through the logic and tell me how I can make the screen jump up to the form, when a user fails validation.