?
Solved

Can a PHP Form display a message below the field if something is typed incorrectly?

Posted on 2008-11-18
47
Medium Priority
?
397 Views
Last Modified: 2013-12-13
I have a PHP form. At the end of the form I am using "MathGuard Security" question so I can stop spammers.

If the answer to the security question is typed in wrong, I want a message to pop up below the form that says "Invalid Security Code. Try Again." Right now it is set up where it goes to a new window. I just want it below the answer field.

I have attached the Code Snippet. You can see on success it goes to another page, and that works perfect.

Any help is GREATLY appreciated.

Thanks,

John


<?php
 
 
/* first we need to require our MathGuard class */
 
require ("ClassMathGuard.php");
 
 
/* this condition checks the user input. Don't change the condition, just the body within the curly braces */
 
 
if (MathGuard :: checkResult($_REQUEST['mathguard_answer'], $_REQUEST['mathguard_code'])) {
 
 
    echo ("<meta http-equiv=\"refresh\" content=\"0;URL=applicationcomplete.php\">"); //insert your code that will be executed when user enters the correct answer
 
} else {
 
    $_SESSION['err']= "there is smething wrong with this field!";
 
    echo ("Invalid security answer. Please try again."); //insert your code which tells the user he is spamming your website
 
}
 
?>

Open in new window

0
Comment
Question by:RiemenDesign
  • 25
  • 21
47 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 22985709
That's a good application for AJAX - since you're posted in the Javascript zone you will probably get a good answer.
0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22985924
You can check out this Spry demo and see if it is what your looking for.

http://labs.adobe.com/technologies/spry/demos/formsvalidation/index.html

0
 

Author Comment

by:RiemenDesign
ID: 22987412
Thanks digitalkandy.

That is what I would be looking for.

Do you know how I would implement that??
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:digitalkandy
ID: 22987983
I couldn't upload a zip file through the functionality on this site, so I put it on my server for you to download. The link below will allow you to download the file, it has basically the same example as you saw in the Spry demo.

http://digitalkandy.net/beta/all-in.zip

This is a shortcut I use whenever I have to build a new form. You can cannibalize the example in the zip folder. The type of the text input (with everything else) is controlled by the code at the bottom of the page, this gives you the functionality to specify an input to validate for date, email etc..

example:
var eMail = new Spry.Widget.ValidationTextField("eMail", "email", {useCharacterMasking:true, regExpFilter:/^[^\'"\*]{0,50}$/, validateOn:["change"]});

var id_name = new Spry.Widget.ValidationTextField("id_name", "input_type(email, date, etc.)", {useCharacterMasking:true, regExpFilter:/^[^\'"\*]{0,50}$/, validateOn:["change"]});
0
 

Author Comment

by:RiemenDesign
ID: 22988375
Thanks again.

Sorry, I am still a little confused on this.

Can you show me what I would need to do to add this in to the current code that is in my original post?

Again, I apologize...just a little confused and it is only due to lack of knowledge.

Thanks,

John
0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22988672
I am so sorry, I just noticed when I re-read the post it looks more like captcha verification than form validation.

Take a look at this link http://www.captcha.biz/how-to-use-captcha.html

If this is what you are looking for just add a "header" into the error message right before the echo that sends back to the form page with a variable on the end of the url (?error=err)

You can capture the variable  $error = $_GET['error'}

then write an if/else statement based on that variable being present in the url, then just echo the message where ever you want it.

Once again really sorry about my poor attention skills there. I have never used Mathguard so I have no idea what functions are running in this file "ClassMathGuard.php". If you really want to stay with Mathguard I would need to see the code or, you might even want to change the title of your question to include it so more people who use it will notice the post.

0
 

Author Comment

by:RiemenDesign
ID: 22989048
No problem at all. I appreciate your help.

I cannot use Captcha because I need to install GD Library on my web server. Unfortunately my host right now wants to charge us $75 per hour to set that up. It is a VSP server so I would have to do that, and I have no clue how to.

I will be sticking with Mathguard. I am still a little confused on how to add this in. I attached the code to ClassMathGuard.php

The form veriies through the first file I posted.

Thanks again!
<?php
 
/**
 * @author Matej Koval 
 * http://www.codegravity.com/projects/mathguard
 *  
 * MathGuard is a PHP class that inserts a small piece of HTML code into your HTML form which requires the user to evaluate an expression consisting of two random numbers. When user submits the form with the answer, the answer is hashed and compared to the security code that has been submitted as well. This way you can easily protect your forms from spambots.
 */
 
 
/** SETTINGS - you can easily modify these constants **/
DEFINE('COLOR', "white");
DEFINE('SIZE', 5);
DEFINE('LINEHEIGHT', 4);
DEFINE('QUESTION', "security question, please solve:");
/** SETTINGS - you can easily modify these constants **/
 
class MathGuard {
 
	/** you can also modify $output to your needs **/
	function produceOutput($prime) {
		$a = rand() % 10; // generates the random number
		$b = rand() % 10; // generates the random number
		$code = MathGuard :: generateCode($a, $b, $prime);
		
		// please don't remove the backlink, thank you
		$output = "<a href='http://www.codegravity.com/'>MathGuard</a> " . QUESTION .
		"<table border='0'><tr><td></td></tr><tr><td><pre style='font-size:" . SIZE . "px; font-weight: bold; color: " . COLOR . "; padding:0px; margin: 0px; line-height:" . LINEHEIGHT . "px;'>\n\n" . MathGuard :: renderExpression($a, $b) . "</pre></td>
				<td><input type='input' name='mathguard_answer' size='2' maxlength='2'/><input type='hidden' name='mathguard_code' value='$code' /></td>
				</tr>
				</table>
				";
 
		return $output;
	}
 
	/** function that converts the decimal number to line of 3 random characters 
	 * @param $dec		decimal number that is being converted to line of 3 random characters
	 * */
	function decToBin($dec) {
		$pattern = "123456789ABCDEFGHIJKLMNOPQRTSTUWXYZ"; //without zero, it was interpreted as an empty space
		$output = "   ";
		$i = 0;
		do {
			if ($dec % 2) {
				$rand = rand() % 34;
				$output {
					2 - $i }
				= $pattern {
					$rand };
			} else {
				$output {
					2 - $i }
				= " ";
			}
			$dec = (int) ($dec / 2);
			$i++;
		} while ($dec > 0);
		return $output;
	}
 
	/** function that renders a final 3x5 matrix consisting of random characters 
	 * @param $a		random number a that renders to the 3x5 matrix consisting of random characters 
	 * @param $b		random number b that renders to the 3x5 matrix consisting of random characters 
	 * */
	function renderExpression($a, $b) {
 
		$number = array (
			array (
				7,
				5,
				5,
				5,
				7
			),
			array (
				2,
				6,
				2,
				2,
				7
			),
			array (
				7,
				1,
				7,
				4,
				7
			),
			array (
				7,
				1,
				7,
				1,
				7
			),
			array (
				4,
				5,
				7,
				1,
				1
			),
			array (
				7,
				4,
				7,
				1,
				7
			),
			array (
				7,
				4,
				7,
				5,
				7
			),
			array (
				7,
				1,
				1,
				1,
				1
			),
			array (
				7,
				5,
				7,
				5,
				7
			),
			array (
				7,
				5,
				7,
				1,
				7
			)
		);
 
		$plus = array (
			0,
			2,
			7,
			2,
			0
		);
		$eq = array (
			0,
			7,
			0,
			7,
			0
		);
 
		for ($line = 0; $line < 5; $line++) {
 
			$output .= MathGuard :: decToBin($number[$a][$line]) . "   " . MathGuard :: decToBin($plus[$line]) . "   " . MathGuard :: decToBin($number[$b][$line]) . "   " . MathGuard :: decToBin($eq[$line]) . "\n";
 
			$output = str_replace("0", " ", $output);
 
		}
 
		return $output;
	}
 
	/** A main hashing function: concat of user's answer, hour and the additional prime number (default 37) */
	function encode($input, $prime) {
		return md5($input . date("H") . $prime);
	}
 
	/** This function generates the hash code from the two numbers 
	 * @param $a 	first number
	 * @param $b	second sumber
	 * @param $prime	additional number to encode with
	 * */
	function generateCode($a, $b, $prime) {
		$code = MathGuard :: encode($a + $b, $prime);
		return $code;
	}
 
	/** This function checks whether the answer and generated security code match 
	 * @param $mathguard_answer		answer the user has entered
	 * @param $mathguard_code		hashcode the mathguard has generated
	 */
	function checkResult($mathguard_answer, $mathguard_code, $prime = 37) {
 
		//		echo("prime; $prime, $mathguard_answer");
		$result_encoded = MathGuard :: encode($mathguard_answer, $prime);
 
		if ($result_encoded == $mathguard_code)
			return true;
		else
			return false;
 
	}
 
	/** this function inserts the two math term into your form, the parameter is optional */
	function insertQuestion($prime = 37) { //default prime is 37, you can change it when specifying the different parameter
 
		$output = MathGuard :: produceOutput($prime);
 
		echo $output;
 
	}
 
	/** this function returns math expression into your form, the parameter is optional 
	 * quite simmilar to insertQuestion, but returns the output as a text instead of echoing
	 */
	function returnQuestion($prime = 37) { //default prime is 37, you can change it when specifying the different parameter
 
		$output = MathGuard :: produceOutput($prime);
 
		return $output;
 
	}
 
}
?>

Open in new window

0
 

Author Comment

by:RiemenDesign
ID: 22989056
Or - if you know of a better way to set the verification up, please feel free to let me know. :) Rather than using mathguard, or captcha since I cannot.
0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22990225
thanks for posting the code. try the following:

1. change the location in the following code to the page where your form is.

<?php
require ("ClassMathGuard.php");
if (MathGuard :: checkResult($_REQUEST['mathguard_answer'], $_REQUEST['mathguard_code'])) {
    echo (""); /
} else {
    $_SESSION['err']= "there is smething wrong with this field!";
    header("Location: http://domain.com/formfile.php?error=err);
}
?>

2. put this on the form page where you want the error message to show up.
<?php
    $error = strstr($_GET['error'], 'err');
if (strlen($error)) {
      echo "nvalid security answer. Please try again.";
} else {
echo " ";
}
?>

the error message is styled to be red, but you can change it whatever you need.


0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22990238
sorry the styling got stripped out of the echo, line should be

echo "Invalid security answer. Please try again.";
0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22990252
ok apparently I'm an idiot I didn't put the code in the right window


echo "<span style=\"font-weight:bold; color:#CC0000;\">Invalid security answer. Please try again.</span>";

Open in new window

0
 

Author Comment

by:RiemenDesign
ID: 22991493
Thanks for your help again!

I get an error though, online 5 of my file.

    echo ("<meta http-equiv=\"refresh\" content=\"0;URL=applicationcomplete.php\">"); /

Any suggestions again? Thanks a lot!!!!


<?php
require ("ClassMathGuard.php");
if (MathGuard :: checkResult($_REQUEST['mathguard_answer'], $_REQUEST['mathguard_code'])) {
    echo ("<meta http-equiv=\"refresh\" content=\"0;URL=applicationcomplete.php\">"); /
} else {
    $_SESSION['err']= "there is smething wrong with this field!";
    header("Location: http://domain.com/application.php?error=err);
}
?>

Open in new window

0
 

Author Comment

by:RiemenDesign
ID: 22991535
OK.
I got it with the code posted below.

Question though. It clears out whatever the user has inputted into the form.

Anyway to make sure their information stays?

Thanks. :)

JOhn
<?php
require ("ClassMathGuard.php");
if (MathGuard :: checkResult($_REQUEST['mathguard_answer'], $_REQUEST['mathguard_code'])) {
    echo ("<meta http-equiv=\"refresh\" content=\"0;URL=applicationcomplete.php\">"); 
} else {
    $_SESSION['err']= "there is smething wrong with this field!";
    header("Location: http://www.systek.com/NEW/application.php?error=err");
}
?>

Open in new window

0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22993982
certainly, you can use the code below to string everything on the end of the url, and in the value of the inputs use the $_GET method to retrieve the data, like you did with the error message.

sorry about the first error you got I should have removed that "/" from the end of the line with the comment.





} else {
$queryString ='';
	 foreach ($_POST as $key => $val) 
	{	$queryString .= (rawurlencode($key). '=' .rawurlencode($val). '&');
	}
	$queryString .= 'error='. $errorNumber;
 
   header("Location: http://www.systek.com/NEW/application.php?".$queryString);
}
?>

Open in new window

0
 

Author Comment

by:RiemenDesign
ID: 22994272
Thanks digital. Where do i place this code at? In the application file?

Thanks again!!

John
0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22994338
The part ($queryString) that get everything into the url goes with your original code right before the header(Location: ) line. see below

no worries, I'm happy i can help. I wouldn't know any of this if it wasn't for this site and the people that helped me.



<?php
require ("ClassMathGuard.php");
if (MathGuard :: checkResult($_REQUEST['mathguard_answer'], $_REQUEST['mathguard_code'])) {
    echo ("<meta http-equiv=\"refresh\" content=\"0;URL=applicationcomplete.php\">"); /
} else {
$queryString ='';
	 foreach ($_POST as $key => $val) 
	{	$queryString .= (rawurlencode($key). '=' .rawurlencode($val). '&');
	}
	$queryString .= 'error='. $errorNumber;
 
   header("Location: http://www.systek.com/NEW/application.php?".$queryString);
}
?>

Open in new window

0
 

Author Comment

by:RiemenDesign
ID: 22994377
I copied that over, and it doesn't work.

the "/" on line 4 was invalid as well. Should that be there?

Anyways, the error message stopped coming up now and nothing is saved like it should be.

Any suggestions? :(

Thanks again. I really aprpeciate your help.
0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22994507
no once again, I should have removed that "/" instead of coping it from the previous post.

Did you put the get statement in the values for your inputs? (let me know if this affects the form when there is no error in the security code, may need to use an if/else statement here)

<input type="text" name="firstname" value="<?php echo  $_GET['firstname']; ?>

the url when error, should look like http://www.systek.com/NEW/application.php?error=err&firstname=steve&input_name=value

the $queryString will place every input onto the end of the url with it's value, but the $_GET will place it into the value.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
<?php
require ("ClassMathGuard.php");
if (MathGuard :: checkResult($_REQUEST['mathguard_answer'], $_REQUEST['mathguard_code'])) {
    echo ("<meta http-equiv=\"refresh\" content=\"0;URL=applicationcomplete.php\">"); 
} else {
$queryString ='';
	 foreach ($_POST as $key => $val) 
	{	$queryString .= (rawurlencode($key). '=' .rawurlencode($val). '&');
	}
	$queryString .= 'error='. $errorNumber;
 
   header("Location: http://www.systek.com/NEW/application.php?error=err&".$queryString);
}
?>

Open in new window

0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22994529
I have no idea why that post just numbered lines down to 14, but please disregard that, the code starts at <?php
0
 

Author Comment

by:RiemenDesign
ID: 22994536
Oh OK. So after each input field I need to put the <?php echo  $_GET['firstname']; ?>

Obviously that depends on the name of each field.

But, I do that for each one?

Let me know if I have that right and then I will go ahead and do that right away!!!!

THanks!!
0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22994603
I'm not sure what you mean by after the input?

The <?php echo  $_GET['firstname']; ?> needs to be in the value for each input, see below

you are correct 'firstname' is just an example, whatever you have named the input is what you need to use to pull the value back out of the url string.

<input name="firstname" type="text" class="contactformField" id="firstname" tabindex="1" value="<?php echo  $_GET['firstname']; ?>" />

Open in new window

0
 

Author Comment

by:RiemenDesign
ID: 22995038
Thanks again. You are a HUGE help.

This is definitely working now.

The only problem is, when the security is invalid, it is not coming up with the error message anymore.

It did when we first started doing this.

Any suggestions on that?

Thanks. :o)
0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22995193
in the header("Location: http://www.systek.com/NEW/application.php?error=err&".$queryString);

do you still have ?error=err& in there?
- it has to be manually set
- and you still have to put the if/else code below in the application.php page

the error=err not part of the form so the $queryString will not automatically put it in the url.
The if/else below will see it and echo the error message

let me know if this solves the issue
<?php
    $error = strstr($_GET['error'], 'err');
if (strlen($error)) {
      echo "nvalid security answer. Please try again.";
} else {
echo " ";
}
?>

Open in new window

0
 

Author Comment

by:RiemenDesign
ID: 22996715
Thanks again.

It is in the application.php file

in the header("Location: http://www.systek.com/NEW/application.php?error=err&".$queryString);  There is NOT ?error=err& in there.

How would I set that?

Thanks again - I can't believe how much help you have been.
0
 

Author Comment

by:RiemenDesign
ID: 22996793
One last quesiton too:

When I click on my state from a drop down menu on my form, the state does not come back. It goes to the "Please Select".

This is the code I have:
 <select name="State" id="State" value="<?php echo  $_GET['State']; ?>">

Should I put the <?php echo  $_GET['State']; ?> for the options??

Example: <option value="AL">AL</option>  In there??

Thanks again!!!!
0
 

Author Comment

by:RiemenDesign
ID: 22996831
I fixed the header to have the error in there:

 header("Location: http://www.systek.com/NEW/application.php?error=err&".$queryString);

Still isn't coming up with the error message...

Thanks again. :)
0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22996903
yes I would try this
Example: <option value="AL">AL</option>  In there??

Do you have one of the options set as default?
<option value="AL" selected>AL</option>
this could be negating the echo.

can you post the full url string in here after the error sends you back to the form page, it will help me see what's going on with the error message.
0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22996917
yes I would try this
Example: <option value="<?php echo  $_GET['State']; ?>"><?php echo  $_GET['State']; ?></option>  In there??

should be <option value="AL">AL</option>
0
 

Author Comment

by:RiemenDesign
ID: 22997372
Thanks!

I am not receiving an error message at all. It bounces back to the form, but not error message is given.

Sorry if I am a bit confused.

Here is the code that processes the file:

<?php
require ("ClassMathGuard.php");
if (MathGuard :: checkResult($_REQUEST['mathguard_answer'], $_REQUEST['mathguard_code'])) {
    echo ("<meta http-equiv=\"refresh\" content=\"0;URL=applicationcomplete.php\">");
} else {
$queryString ='';
       foreach ($_POST as $key => $val)
      {      $queryString .= (rawurlencode($key). '=' .rawurlencode($val). '&');
      }
      $queryString .= 'error='. $errorNumber;
 
   header("Location: http://www.systek.com/NEW/application.php?error=err&".$queryString);
}
?>


Here is the code that I have IN the application.php file:

<?php
    $error = strstr($_GET['error'], 'err');
if (strlen($error)) {
      echo "nvalid security answer. Please try again.";
} else {
echo " ";
}
?>


Thanks for your help.
0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22997459
that all looks fine, can you paste the url string out of the address bar after the error. What I want to see is if there is a problem with the way the queryString is placing all the keys and values into the url.

I'm looking for you to pull the whole url right out of the address bar after the error sends you back to the form page

example:
http://www.systek.com/NEW/application.php?error=err&firstname=steve&lastname=bob.........

you still have my lousy misspelling in there, sorry about that.
echo "nvalid security answer. Please try again.";
should be
echo "Invalid security answer. Please try again.";
you can change anything between the two quote marks on that line so the message will read whatever you want.
0
 

Author Comment

by:RiemenDesign
ID: 22997497
Here you go:

Thanks. :)
http://www.systek.com/NEW/application.php?error=err&date=11%2F19%2F08&FirstName=&LastName=&MiddleName=&SSN=&email=&Street=&City=&State=%20&Zip=&Telephone=&ReferredBy=&Position=&StartDate=&Salary=%24&Employed=%20&Inquire=%20&Applied=%20&WhenDidYouApply=&NameGrammar=&LocationGrammar=&LastYearGrammar=&GraduateGrammar=%20&SubjectsGrammar=&NameHS=&LocationHS=&LastYearHS=&GraduateHS=%20&SubjectsHS=&NameCollege=&LocationCollege=&LastYearCollege=&GraduateCollege=%20&SubjectsCollege=&NameTrade=&LocationTrade=&LastYearTrade=&GraduateTrade=%20&SubjectsTrade=&SpecialStudy=&ForeignLanguage=&ForeignRead=&ForeignWrite=&Activities=Exclude%20organizations%20the%20name%20or%20character%20of%20which%20indicates%20the%20race%2C%20color%2C%20or%20national%20origin%20of%20its%20members.&DateFromEmployerOne=&DateToEmployerOne=&EmployerOneName=&supervisornameone=&supervisorphoneone=&contactone=Please%20Select&SalaryEmployerOne=%24&PositionEmployerOne=&ReasonEmployerOne=&DateFromEmployerTwo=&DateToEmployerTwo=&EmployerTwoName=&supervisornametwo=&supervisorphonetwo=&contacttwo=Please%20Select&SalaryEmployerTwo=%24&PositionEmployerTwo=&ReasonEmployerTwo=&DateFromEmployerThree=&DateToEmployerThree=&EmployerThreeName=&supervisornamethree=&supervisorphonethree=&contactthree=Please%20Select&SalaryEmployerThree=%24&PositionEmployerThree=&ReasonEmployerThree=&DateFromEmployerFour=&DateToEmployerFour=&EmployerFourName=&supervisornamefour=&supervisorphonefour=&contactfour=Please%20Select&SalaryEmployerFour=%24&PositionEmployerFour=&ReasonEmployerFour=&ReferenceOneName=&ReferenceOneAddress=&referenceonephone=&referenceoneemail=&BusinessPersonalOneReference=%20&ReferenceOneYearsAquainted=&ReferenceTwoName=&ReferenceTwoAddress=&referenceonephone2=&referencetwoemail=&BusinessPersonalTwoReference=%20&ReferenceTwoYearsAquainted=&ReferenceThreeName=&ReferenceThreeAddress=&referencethreephone=&referencethreeemail=&BusinessPersonalThreeReference=%20&ReferenceThreeAquainted=&GSC=%20&GSCDenied=%20&mathguard_answer=1&mathguard_code=b682b7950b5812d990b973708d5c73a1&Submit=Submit%20Application&error=

Open in new window

0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22997596
it looks like I have you doubling error in the string, try the code below to replace what is in the process file.
<?php
require ("ClassMathGuard.php");
if (MathGuard :: checkResult($_REQUEST['mathguard_answer'], $_REQUEST['mathguard_code'])) {
    echo ("<meta http-equiv=\"refresh\" content=\"0;URL=applicationcomplete.php\">"); 
} else {
$queryString ='';
       foreach ($_POST as $key => $val) 
      {      $queryString .= (rawurlencode($key). '=' .rawurlencode($val). '&');
      }
      $queryString .= 'error=err'. $errorNumber;
 
   header("Location: http://www.systek.com/NEW/application.php?".$queryString);
}
?>

Open in new window

0
 
LVL 1

Accepted Solution

by:
digitalkandy earned 2000 total points
ID: 22997626
or now that I look at it some more this may also work
<?php
require ("ClassMathGuard.php");
if (MathGuard :: checkResult($_REQUEST['mathguard_answer'], $_REQUEST['mathguard_code'])) {
    echo ("<meta http-equiv=\"refresh\" content=\"0;URL=applicationcomplete.php\">"); 
} else {
$queryString ='';
       foreach ($_POST as $key => $val) 
      {      $queryString .= (rawurlencode($key). '=' .rawurlencode($val). '&');
      }
 
   header("Location: http://www.systek.com/NEW/application.php?error=err&".$queryString);
}
?>

Open in new window

0
 

Author Comment

by:RiemenDesign
ID: 22997695
Hey for the state selection, would it be like this?

<option value="<?php echo  $_GET['State']; ?>">AL<?php echo  $_GET['State']; ?></option>

I ahvent tried it yet. Would hta twork?
0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22997800
<option value="<?php echo  $_GET['State']; ?>"> <?php echo  $_GET['State']; ?> </option>

that should work as long as you don't have one of the options marked as the default (selected) in the option tag;
example:
<option value="please select one" selected >Please select one</option>
0
 

Author Comment

by:RiemenDesign
ID: 22997813
OK. But wouldnt that take away the options for the states?

Error code works now!!!
0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22997939
you only want one of the options to be (example in code window)
<option value="<?php echo  $_GET['State']; ?>"> <?php echo  $_GET['State']; ?> </option>

it will appear blank unless it can pull the state out of the url string, might even be a good idea to use this one as the default (selected) that way they have to choose their state unless the form can pull the value out of the url.

in which case it would be
<option value="<?php echo  $_GET['State']; ?>" selected> <?php echo  $_GET['State']; ?> </option>

<select id="country" name="country" class="contactselectDrop" tabindex="12">
      <option value="<?php echo  $_GET['State']; ?>" selected> <?php echo  $_GET['State']; ?> </option>
      <option value="AF">Afghanistan</option>
      <option value="AL">Albania</option>
      <option value="DZ">Algeria</option>
      <option value="AS">American Samoa</option>
      <option value="AD">Andorra</option>
      <option value="AO">Angola</option>
      <option value="AI">Anguilla</option>
</select>

Open in new window

0
 

Author Comment

by:RiemenDesign
ID: 22998022
Hmmm...that didn't work either.

Any other suggestions?

Everything else is great, by the way!! Thank you.

This is my last problem I am having.
0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22998137
I got nothing else off the top of my head, but I can look into it tonight. (have to run into a meeting soon)

I normally never use the select box for State codes just a text input, but that's a personal preference and I can totally see why you would want to do it that way.

if your open to it, or you have a tight deadline, I would suggest changing it to a text input and then just echo the $_GET['state'}, as this part might take a while to figure out, but I'm not giving up on it and neither should you.

keep monitoring the question, I post as soon as I have something for you.
0
 
LVL 1

Assisted Solution

by:digitalkandy
digitalkandy earned 2000 total points
ID: 22999739
so here's an idea what if we try to make one of the options "selected" instead of trying to echo the value. try the code below.

Basically if the value is in the url string it echos the "selected" designation into the option.

for this to work none of the options for the select box can have "selected' as the default state.

Let me know if this works for you, for me this is theoretical ground
<select name="state">
<option value="AL"<? if($_GET['state'] == 'AL'){ echo " SELECTED"; } ?>>AL</option> 
<option value="MN"<? if($_GET['state'] == 'MN'){ echo " SELECTED"; } ?>>MN</option>
<option value="MI"<? if($_GET['state'] == 'MI'){ echo " SELECTED"; } ?>>MI</option>
<option value="CA"<? if($_POST['state'] == 'CA'){ echo " SELECTED"; } ?>>CA</option>
</select>

Open in new window

0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 22999744
whoops, last option should read

<option value="CA"<? if($_GET['state'] == 'CA'){ echo " SELECTED"; } ?>>CA</option>

sorry about that

0
 

Author Closing Comment

by:RiemenDesign
ID: 31517884
Excellent. WONDERFUL JOB!!!!

Saved me a big big headache.
0
 

Author Comment

by:RiemenDesign
ID: 23000959
Thanks again. Job well done!!
0
 

Author Comment

by:RiemenDesign
ID: 23007248
Hi Digital - thanks again for helping me.

I am having one final problem.

The information does not transmit through email anymore.

I get the email, but it comes through without the user input from the form.

Any suggestions????

Thanks!
0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 23008537
Hey RD,

nothing we did should have affected your mail function, but I'll look through the ClassMathGuard.php to see if it's in there. If not it may be in the applicationcomplete.php file.

It sound like the values are just not being placed inside the mail body.


0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 23009466
can you look in the  applicationcomplete.php and see if the "mail" function is in there?

0
 
LVL 1

Expert Comment

by:digitalkandy
ID: 23028586
I haven't heard back from you, is everything working?
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses
Course of the Month16 days, 17 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question