0

Can ignore other post not sure why i closed it, not solved lol, not enough coffee too much looking at php anyway.

I have this form I'm working on and found something interesting

attempt1
this way works exactly how I want, which is nothing in the input boxes and no error messages on loading the registration form, once submit button is pressed the empty fields have a message appear next to them, the only problem is it does not validate on the w3 website

<label>Username</label><br />
<input name="name" type="text"  value="<?php if(isset($_POST['name'])) echo $_POST['name'] ?>"/>
<?php if (!empty($arrErrors['name'])) echo '<span class="errortext">'.$arrErrors['name'].'</span>';?>
<br />

error message is, all errors underline the " after the word value

#  Error  Line 78, Column 47: XML Parsing Error: Unescaped '<' not allowed in attributes values

…nput name="name" type="text"  value="<?php if(isset($_POST['name'])) echo $_P

✉
# Error Line 78, Column 47: XML Parsing Error: attributes construct error

…nput name="name" type="text"  value="<?php if(isset($_POST['name'])) echo $_P

✉
# Error Line 78, Column 47: XML Parsing Error: Couldn't find end of Start Tag input line 78

…nput name="name" type="text"  value="<?php if(isset($_POST['name'])) echo $_P

attempt 2
this code validates

<label>Username</label><br />
<input name="name" type="text"  value="&lt;?php if(isset($_POST['name'])) echo $_POST['name'] ?&gt;"/>
 <?php if (!empty($arrErrors['name'])) echo '<span class="errortext">'.$arrErrors['name'].'</span>';?>
<br />

however on loading the form this code appears in the text area which makes it look very ugly, it does this because of the < being changed to &lt; and > to &gt; and simply treats it as input

<?php if(isset($_POST['name'])) echo $_POST['name'] ?>

attempt 3
which validates

<label>Username</label><br />
<?php echo "<input name=\"name\" type=\"text\"  value=\"" if(isset($_POST['name'])) echo $_POST['name'], "\" />";
 if (!empty($arrErrors['name'])) echo '<span class="errortext">'.$arrErrors['name'].'</span>';
echo "<br />";
?>

but throws the following parse error, with line 79 being the line with input tag

Parse error: parse error, expecting `','' or `';'' in C:\wamp\www\music good copies\register.php on line 79

what i need is to make the outcome of attempt 1 which is empty form on load and error messages when empty fields are attempted to be submitted with the code like attempt 3 so that it validates

validation is not critical as its for a php site that is hosted locally, however for future projects I would like to know the correct way.

cheers

3
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by cwarn23
0

Try attempt 4 the following:

<label>Username</label><br />
<input name="name" type="text"  value="<?php if(isset($_POST['name'])) echo $_POST['name'] ?>"/>
<?php echo (!empty($arrErrors['name']))? '<span class="errortext">'.$arrErrors['name'].'</span>':''; ?>
<br />

Edited by cwarn23: n/a

0

Try attempt 4 the following:

<label>Username</label><br />
<input name="name" type="text"  value="<?php if(isset($_POST['name'])) echo $_POST['name'] ?>"/>
<?php echo (!empty($arrErrors['name']))? '<span class="errortext">'.$arrErrors['name'].'</span>':''; ?>
<br />

works how I want except it doesn't validate

value="<?php if(isset($_POST['name'])) echo $_POST['name'] ?>

this line is the problem and in particular the " after value=, it throws the same 3 errors that attempt 1 did.

0

works how I want except it doesn't validate

value="<?php if(isset($_POST['name'])) echo $_POST['name'] ?>

this line is the problem and in particular the " after value=, it throws the same 3 errors that attempt 1 did.

I didn't spot that piece of php code. Should be as follows:

<label>Username</label><br />
<input name="name" type="text"  value="<?php echo (isset($_POST['name']))? $_POST['name']:''; ?>"/>
<?php echo (!empty($arrErrors['name']))? '<span class="errortext">'.$arrErrors['name'].'</span>':''; ?>
<br />

or

<label>Username</label><br />
<input name="name" type="text"  value="
<?php echo (isset($_POST['name']))? $_POST['name']:''; ?>
"/>
<?php echo (!empty($arrErrors['name']))? '<span class="errortext">'.$arrErrors['name'].'</span>':''; ?>
<br />

Edited by cwarn23: code tags lol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.