Jump to content

Php Adds Slash In Each Input


mostafatalebi

Recommended Posts

hello everybody

 

I have made a form with several inputs and made a php script to echo a variable in the value of each input, something like this:

 

<?php $aVariable = "";

<input name='test' value=<?php echo $aVariable ?>

 

but what I get at the end is an input with a slash in it. I should get an empty input indeed.

Link to comment
Share on other sites

I mean I have made a form in HTML, static, and I have added several inline php script.

I have set the value of the each text input to this inline script:

<?php
$thisInputValue = htmlentities($_Post['username'], ENT_QUOTES];
echo $thisInputValue;
?>

Everything works fine, but the problem is that when i run the page for the first time, there is a "/" in the inputs. This is quite little strange, but seem to be common.

my input eventually looks like this:

<html>
<input type="text" value="/" />
</html>

Edited by mostafatalebi
Link to comment
Share on other sites

<form action="" method="post" name="register_form">
<label for="first_name"> First Name </label>
<input type="text" name="first_name" class="inputs" value=<?php echo $input['firstname']; ?>/>
<?php
// get the value of the variables
if($error['firstname_alert'] != "")
{
echo "<div id='required'>" . $error['firstname_alert'] . "</div>";
}
?> <br /><br />

This is a part of the script. The rest is the duplication of this part and making other inputs. so this showa you almost the entire stracture of my register_view.php. this file then is included in another register.php file and is shown. EVERYTHING works fine but the only problem is the forward slash added to the input.

Also here is the variables for all of my PHP scripts:

 

$error;// now the elements
$error['register_alert'] = ""; $error['firstname_alert'] = " "; $error['lastname_alert'] = ""; $error['password_alert'] = ""; $error['password2_alert'] = "";
$error['email_alert'] = ""; // all the elements for erroring while registration
$input;
$input['firstname'] = ""; $input['lastname'] = ""; $input['password'] = ""; $input['password2'] = ""; $input['email'] = ""; $input['information'] = ""; // all the elements for

Edited by mostafatalebi
Link to comment
Share on other sites

Adding quotes around the value attribute's value should get rid of the issue.

 

<input type="text" name="first_name" class="inputs" value="<?php echo $input['firstname']; ?>" />

 

Also note that the <label> tag isn't really doing anything. You need to add an id attribute to the <input> tag.

 

<input type="text" name="first_name" id="first_name" class="inputs" value="<?php echo $input['firstname']; ?>" />

 

Now clicking the label should put focus into the first_name field.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.