helloworld
helloworld

Reputation: 195

Laravel form displayed as raw text

My problem is probably related to server configuration problem. This is the issue. I am developing a Laravel website that works fine when developing on my local machine (using the laradock docker environment). I wanted to run it on a small local machine so I turned on a fresh Ubuntu 16.04 server and installed docker on it. Checked out my code and ran composer install.

After going to the main registration page, I see that parts of the registration form are displayed as raw text :

laravel error - displaying form data as raw html

I don't see any errors when using the developers page and also no errors in the php-fpm, workspace or nginx container from laradock that hosts the website. Any idea?

code:

<?php
    $ip = get_ip_address();

    $countries = [
        "Afghanistan" => "Afghanistan",
        "Albania" => "Albania",
        "Zimbabwe" => "Zimbabwe"
    ];
 ?>

 @extends('layouts.app')

 @section('content')
 <div class="container">
   <div class="row">
     <div class="col-md-8 col-md-offset-2">
       <div class="panel panel-default">
         <div class="panel-heading">Register</div>
         <div class="panel-body">
           <form class="form-horizontal" role="form" method="POST" action="{{ route('register') }}">
             {{ csrf_field() }}

             <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
               <label for="name" class="col-md-4 control-label">Name</label>

               <div class="col-md-6">
                 <input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}" required autofocus>

                 @if ($errors->has('name'))
                 <span class="help-block">
                   <strong>{{ $errors->first('name') }}</strong>
                 </span>
                 @endif
               </div>
             </div>

             <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
               <label for="email" class="col-md-4 control-label">E-Mail Address</label>

               <div class="col-md-6">
                 <input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required>

                 @if ($errors->has('email'))
                 <span class="help-block">
                   <strong>{{ $errors->first('email') }}</strong>
                 </span>
                 @endif
               </div>
             </div>

             <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
               <label for="password" class="col-md-4 control-label">Password</label>

               <div class="col-md-6">
                 <input id="password" type="password" class="form-control" name="password" required>

                 @if ($errors->has('password'))
                 <span class="help-block">
                   <strong>{{ $errors->first('password') }}</strong>
                 </span>
                 @endif
               </div>
             </div>

             <div class="form-group">
               <label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>

               <div class="col-md-6">
                 <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
               </div>
             </div>

             <div class="form-group">
               <label for="country" class="col-md-4 control-label">Select your country</label>

               <div class="col-md-6">
                 {{Form::select("country", $countries, null, ['type' => 'text','class' => 'form-control','placeholder' => 'Pick your country...'])}}
               </div>

               @if ($errors->has('country'))
               <span class="help-block">
                 <strong>{{ $errors->first('country') }}</strong>
               </span>
               @endif
             </div>

             {{ Form::hidden('ip', $ip) }}

             <div class="form-group">
               <div class="col-md-6 col-md-offset-4">
                 <button type="submit" class="btn btn-primary">
                   Register
                 </button>
               </div>
             </div>

           </form>
         </div>
       </div>
     </div>
   </div>
 </div>
 @endsection

<?php

function get_ip_address() {
  // check for shared internet/ISP IP
  if (!empty($_SERVER['HTTP_CLIENT_IP']) && validate_ip($_SERVER['HTTP_CLIENT_IP'])) {
     return $_SERVER['HTTP_CLIENT_IP'];
  }

  // check for IPs passing through proxies
  if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    // check if multiple ips exist in var
    if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',') !== false) {
      $iplist = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
      foreach ($iplist as $ip) {
        if (validate_ip($ip))
        return $ip;
      }
    } else {
      if (validate_ip($_SERVER['HTTP_X_FORWARDED_FOR']))
      return $_SERVER['HTTP_X_FORWARDED_FOR'];
    }
  }
  if (!empty($_SERVER['HTTP_X_FORWARDED']) && validate_ip($_SERVER['HTTP_X_FORWARDED']))
    return $_SERVER['HTTP_X_FORWARDED'];
  if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))
    return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
  if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && validate_ip($_SERVER['HTTP_FORWARDED_FOR']))
    return $_SERVER['HTTP_FORWARDED_FOR'];
  if (!empty($_SERVER['HTTP_FORWARDED']) && validate_ip($_SERVER['HTTP_FORWARDED']))
    return $_SERVER['HTTP_FORWARDED'];

  // return unreliable ip since all else failed
  return $_SERVER['REMOTE_ADDR'];
}
?>

Upvotes: 1

Views: 1093

Answers (1)

Douwe de Haan
Douwe de Haan

Reputation: 6646

All the values echoed with {{ }} are sent through the htmlentities function of PHP. If you want to skip that, than you should use another notation:

{!! $unescaped_html !!}

Source

Upvotes: 4

Related Questions