Note that there are some explanatory texts on larger screens.

plurals
  1. POhtml form input value, will not echo php object function htmlspecialchars
    primarykey
    data
    text
    <p>I have implemented child classes to process user input inherited from a parent class which handles the database connections, read and write. </p> <p>In my parent class I have a function called 'hsc' which handles 'htmlspecialchars' and the function filters user input and returns the string.</p> <p>hsc function</p> <pre><code>public function hsc($string) { return htmlspecialchars($string); } </code></pre> <p>I am having a problem with my signup form. When I call the above function on the sign_up object, even before the form is submited the form breaks, then will only output the first label.</p> <p>output</p> <p>Your First Name (rest of the form is missing)</p> <p>problem code</p> <pre><code> value="&lt;?php echo $sign_up-&gt;hsc($_POST['name']);?&gt;" /&gt; </code></pre> <p>if I remove the above php code from value, the form displays correctly, also i can echo out text within the php tags, so the problem seems to be with the function? </p> <p>While trying to figure this out, am I using the correct approach, ie, using classes too validate user input?</p> <p>Hope someone can help</p> <p>Thanks</p> <p>please see the code I am using for the form below</p> <pre><code> &lt;?php include('./classes/signup_class.php'); if(isset($_POST['submit'])) { //require('./classes/signup_class.php'); try { $sign_up = new Signup_User(); $sign_up-&gt;processUserInput(); $errors = $sign_up-&gt;getErrorMessages(); }catch (Exception $e) { echo $e-&gt;getMessage(); } } ?&gt; &lt;form id="sign_up" method="post" action=""&gt; &lt;p&gt; &lt;label for="name"&gt;Your First Name&lt;/label&gt; &lt;input name="name" id="name" type="text" value="&lt;?php echo $sign_up-&gt;hsc($_POST['name']);?&gt;" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="surname"&gt;Your Last Name&lt;/label&gt; &lt;input name="surname" id="surname" type="text" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="email"&gt;Your Email Address&lt;/label&gt; &lt;input name="email" id="email" type="text"/&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="emailconf"&gt;Confirm Your Email Address&lt;/label&gt; &lt;input name="emailconf" id="emailconf" type="text"/&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="gender"&gt;Your Gender&lt;/label&gt; &lt;select class="gender_select" name="gender"&gt; &lt;option value="female"&gt;Female&lt;/option&gt; &lt;option value="male"&gt;Male&lt;/option&gt; &lt;/select&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="password"&gt;Choose Your Password (8 characters)&lt;/label&gt; &lt;input name="password" id="password" type="password"&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="passconf"&gt;Confirm Your Password&lt;/label&gt; &lt;input name="passconf" id="passconf" type="password"&gt; &lt;/p&gt; &lt;input name="submit" id="submit" type="submit" value="signup" class="sign_up" &gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload