oddball25 Posted January 25, 2010 Share Posted January 25, 2010 Hey I cannot get my php validation code to run without errors. I get the following error: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in... I have 'validate.php' which sets the validation functions for each and i call this in 'require_once' at the start of my main php page. I have a switch statement that when 'formchoiceone' is chosen it echos the form and the validation. I have tested this code in a standard php file (one that does not output the form and validation in an echo) and it all works fine but having it inside the echo is producing errors. Code is below: validate.php <?php function validateInputOne($one){ //if it's NOT valid if(ereg('[^A-Za-z]', $one)) return false; //if it's valid else return true; } function validateInputTwo($two){ //if it's NOT valid if(ereg('[^0-9]', $two)) return false; //if it's valid else return true; } ?> main php page <?php session_start(); require_once("validate.php"); switch ($choice) { case 'formchoiceone': echo ' <div id=form> <form name="formone" method="post" action=""> if( isset($_POST['send']) && (!validateInputOne($_POST['one']) || !validateInputTwo($_POST['two]) ) ): <div id="error"> if(!validateInputOne($_POST['one'])): <p class="cform">[Please enter Letters Only]</p> endif if(!validateInputTwo($_POST['two'])): <p class="cform">[Please enter Numbers Only]</p> endif </div> elseif(isset($_POST['send'])): <div id="error" class="valid"> </div> endif <p class="cform">Name<input id="one" name="one" type="text"/></p> <p class="cform">Age<input id="two" name="two" type="text"/></p> <input id="send" name="send" class="submitbutton" type="submit" value="Send"></input> </form> </div>'; break; ?> Any ideas on this? Had me stuck for days now... Thanks Jon Quote Link to comment https://forums.phpfreaks.com/topic/189714-my-input-validation-code-causing-errors/ Share on other sites More sharing options...
iScript Posted January 25, 2010 Share Posted January 25, 2010 You can see the problem in the coding color... you echoed all the if's and all the PHP statment in the switch... Quote Link to comment https://forums.phpfreaks.com/topic/189714-my-input-validation-code-causing-errors/#findComment-1001225 Share on other sites More sharing options...
oddball25 Posted January 25, 2010 Author Share Posted January 25, 2010 Is there a logical way to solve this then or is the entire code not possible to do? Quote Link to comment https://forums.phpfreaks.com/topic/189714-my-input-validation-code-causing-errors/#findComment-1001226 Share on other sites More sharing options...
laffin Posted January 25, 2010 Share Posted January 25, 2010 logical way: when using '/" remember the closign '/" if you look at your post, ya will see ya missed the closing quote. Quote Link to comment https://forums.phpfreaks.com/topic/189714-my-input-validation-code-causing-errors/#findComment-1001231 Share on other sites More sharing options...
Furt Posted January 25, 2010 Share Posted January 25, 2010 maybe this way will work. <?php session_start(); require_once("validate.php"); switch ($choice) { case 'formchoiceone': echo ' <div id=form> <form name="formone" method="post" action="">'; if( isset($_POST['send']) && (!validateInputOne($_POST['one']) || !validateInputTwo($_POST['two']) ) ): echo ' <div id="error">'; if(!validateInputOne($_POST['one'])): echo' <p class="cform">[Please enter Letters Only]</p>'; endif if(!validateInputTwo($_POST['two'])): echo ' <p class="cform">[Please enter Numbers Only]</p>'; endif echo '</div>'; elseif(isset($_POST['send'])): echo '<div id="error" class="valid"></div>'; endif echo ' <p class="cform">Name<input id="one" name="one" type="text"/></p> <p class="cform">Age<input id="two" name="two" type="text"/></p> <input id="send" name="send" class="submitbutton" type="submit" value="Send"></input> </form> </div>'; break; ?> Quote Link to comment https://forums.phpfreaks.com/topic/189714-my-input-validation-code-causing-errors/#findComment-1001237 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.