Jump to content


Photo

Form as variable


  • Please log in to reply
3 replies to this topic

#1 dennisbillings

dennisbillings
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 February 2006 - 04:42 PM

I want to make the following form set as a variable I can't get it to work and was hoping someone could give me a hand. The while loop is giving me headaches via parse errors and I can't figure out why. Any help would be greatly appreciated

$form .= "<fieldset><form method=\"post\" action=\"<?php echo {$_SERVER['PHP_SELF']};?>\"
onsubmit=\"return validate(uname,pass,pass1,fname,lname,email);\">
<legend>User Registration: </legend>
<table><tr><td>
Login Name:</td><td> <input type=\"text\" name=\"uname\" value=\"\"></td></tr><tr><td>
Pass: </td><td><input type=\"password\" name=\"pass\" value=\"\"></td></tr><tr><td>
Confirm Pass: </td><td><input type=\"password\" name=\"pass1\" value=\"\"></td></tr><tr><td>
First Name: </td><td><input type=\"text\" name=\"fname\" value=\"\"></td></tr><tr><td>
Last Name: </td><td><input type=\"text\" name=\"lname\" value=\"\"></td></tr><tr><td>
E-mail: </td><td><input type=\"text\" name=\"email\" value=\"\"></td></tr><tr><td>
clan: </td><td> <select name=\"clanname\" value=\"\">";


$form .= "while($row = mysql_fetch_assoc($result)){
echo '<option value=/"' . htmlspecialchars($row['clanname']) . '/">' .
$row['clanname'] . '</option>';
}";


$form .= "</td></tr><tr><td>
<input type=\"checkbox\" name=\"emaillist\" value=\"1\"></td><td> If you would
like to receive an email informing you of the next tourney check this box.
</td></tr><tr><td></td><td>
* You must have a clan registered to register as a
user.</td></tr><tr><td></table>
<input type=\"submit\" value=\"submit\" >
</form></fieldset>";

#2 Ge64

Ge64
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 27 February 2006 - 04:45 PM

[!--quoteo(post=349874:date=Feb 27 2006, 05:42 PM:name=dennisbillings)--][div class=\'quotetop\']QUOTE(dennisbillings @ Feb 27 2006, 05:42 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I want to make the following form set as a variable I can't get it to work and was hoping someone could give me a hand. The while loop is giving me headaches via parse errors and I can't figure out why. Any help would be greatly appreciated

$form .= "<fieldset><form method=\"post\" action=\"<?php echo {$_SERVER['PHP_SELF']};?>\"
onsubmit=\"return validate(uname,pass,pass1,fname,lname,email);\">
<legend>User Registration: </legend>
<table><tr><td>
Login Name:</td><td> <input type=\"text\" name=\"uname\" value=\"\"></td></tr><tr><td>
Pass: </td><td><input type=\"password\" name=\"pass\" value=\"\"></td></tr><tr><td>
Confirm Pass: </td><td><input type=\"password\" name=\"pass1\" value=\"\"></td></tr><tr><td>
First Name: </td><td><input type=\"text\" name=\"fname\" value=\"\"></td></tr><tr><td>
Last Name: </td><td><input type=\"text\" name=\"lname\" value=\"\"></td></tr><tr><td>
E-mail: </td><td><input type=\"text\" name=\"email\" value=\"\"></td></tr><tr><td>
clan: </td><td> <select name=\"clanname\" value=\"\">";
$form .= "while($row = mysql_fetch_assoc($result)){
echo '<option value=/"' . htmlspecialchars($row['clanname']) . '/">' .
$row['clanname'] . '</option>';
}";
$form .= "</td></tr><tr><td>
<input type=\"checkbox\" name=\"emaillist\" value=\"1\"></td><td> If you would
like to receive an email informing you of the next tourney check this box.
</td></tr><tr><td></td><td>
* You must have a clan registered to register as a
user.</td></tr><tr><td></table>
<input type=\"submit\" value=\"submit\" >
</form></fieldset>";
[/quote]

What errors do you get? It probably doesnt work because you use $form = " ..... "; but you also use " in the HTML. Whenever that happens I use ' instead of " , so like $html = '<div align="center">';


#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 27 February 2006 - 05:23 PM

Your code doesn't work because your string has escapes into PHP while you're already in PHP.

The question I have for you is why do you want to do this?

Here is one solution to your problem:
<?php
$form .= '<fieldset><form method="post" action="' . $_SERVER['PHP_SELF'] . '"
onsubmit="return validate(uname,pass,pass1,fname,lname,email);">
<legend>User Registration: </legend>
<table><tr><td>
Login Name:</td><td> <input type="text" name="uname" value=""></td></tr><tr><td>
Pass: </td><td><input type="password" name="pass" value=""></td></tr><tr><td>
Confirm Pass: </td><td><input type="password" name="pass1" value=""></td></tr><tr><td>
First Name: </td><td><input type="text" name="fname" value=""></td></tr><tr><td>
Last Name: </td><td><input type="text" name="lname" value=""></td></tr><tr><td>
E-mail: </td><td><input type="text" name="email" value=""></td></tr><tr><td>
clan: </td><td> <select name="clanname" value="">";
while($row = mysql_fetch_assoc($result)){
$form .= '<option value="' . htmlspecialchars($row['clanname']) . '">' . $row['clanname'] . '</option>';
}
$form .= '</td></tr><tr><td>
<input type="checkbox" name="emaillist" value="1"></td><td> If you would
like to receive an email informing you of the next tourney check this box.
</td></tr><tr><td></td><td>
* You must have a clan registered to register as a
user.</td></tr><tr><td></table>
<input type="submit" value="submit" >
</form></fieldset>';
?>

Ken

#4 dennisbillings

dennisbillings
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 February 2006 - 11:33 PM

Thanks guys, appreciate the help. Ken to answer your question of why I want to create a form as a variable here it is.

I want to validate my form input to make sure the fields are all filled out and the password and confirm password match.


IF (isset($_REQUEST["submit"])){
   
   IF (isset($_REQUEST["UserName"])){
   $UserName = $_REQUEST["UserName"];
   }ELSE{
   $message .="You forgot to enter your User Name. /n $form";
   }
// And the IF else statements will continue to check all the fields and then if there is an error message I don't
// want the data to be submitted until the fields are corrected.
   }ELSE{
   $form;

Basically I want the form to appear until the data is submitted correctly. Then the "Thank you for registering statement." and no form. I'm familiar with how to use javascript to check form input and create alerts until the data is correct but I was trying find a way to validate inside of php. I was having trouble figuring out a good way to check the fields and hold sending the data to MySQL until the fields were correct.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users