Support the ongoing development of Laravel.io →
posted 8 years ago
Views Forms
Last updated 1 year ago.
0

Now upgraded to 5.2 - doesn't solve the issue

0

I'd suspect the contents of your public/.htaccess file on the server and your localhost differ or the 2 machines have different installations (windows / linux etc). To start can you say what happens in your code if you submit xyz.com/test.mp3 (without any http) and also with a www prefix (www.xyz.com/test.mp3)

0

Thanks for your ideas :)

I'm afraid the .htaccess files are identical - I don't think I've altered them at all:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Trying your examples:

xyz.com/test.mp3 WORKS www.xyz.com/test.mp3 WORKS

As I said, all it takes is the removal of a colon or one of the forward slashes from http:// and then the input is accepted.

Would that be affected by .htaccess - the form is not being directed to a url, it is merely receiving a url as input from a form field?

Both machines are running Linux - my local machine is Linux Mint and I'm not sure what distro my host is using, but it is Linux.

Any other ideas?

Last updated 8 years ago.
0

Some more detail: Here is the form

<form action="http://xyz.com/14/series/12/music"; method="POST" class="form-horizontal">
  <input type="hidden" name="_token" id="csrf-token" value="iYnoHRbjD1rIuFY7HFTGk6jJwmdl2UOHixqAydBp" />
  <input name="mp3" type="text" id="mp3">
  <input type="submit" value="Add MP3"> 
</form>

And the relevant routes:

Route::post('{venue}/series/{series}/music',['uses'=>'MusicController@store','as'=>'venue.series.music.store']);

Route::get('{venue}/series/{series}/music',['uses'=>'MusicController@index','as'=>'venues.series.music.index']);

What is happening is that when a full url (including http://) is submitted from the mp3 field, the data is routed using the GET method (ie to the index page, without writing to the database). When a url is submitted without http:// at the front (or with a letter missing, or even with a space in front of http://) it uses the POST method as intended and writes to the database.

How can anything I type in a text box have any impact on anything prior to reaching the controller?

Stumped

Last updated 8 years ago.
0

Hi bishopm,

Can you try using (and also with a preceding /)

<form action="14/series/12/music" method="POST" class="form-horizontal">

I also use mint ;) I'm presuming this is a testbed. I also presume xyz.com is your site? I still think its an issue with server configuration rather than laravel but if the above helps then all the better.

0

Yes - I just changed the site for the public post. With apologies to whoever owns xyz.com :)

<form action="/14/series/12/music/" method="POST" class="form-horizontal">

goes to the index method on the Controller (ie as if using the GET method)

<form action="14/series/12/music/" method="POST" class="form-horizontal">

brings up a 404 - because the url it tries to access is http://xyz.com/14/series/12/music/14/series/12/music/

I agree the difference must be a server issue because the same code works on a different machine. What I can't get my head around is how the content of a form field could change the method of the form and how changing that content by a single character can yield a different result...

Thanks for your help

0

sorry if i am answering a wrong question, but my understanding is that potentially the url localhost on your local system is different from the server one and its not auto generating the correct url for your form submit...

Have you tried to use something like

<form action="{{url('14/series/12/music'}}" method="POST" class="form-horizontal">

or use a named route and let laravel generate the route url

<form action="{{route('music.series.named.route', ['series' => '14', 'music' => '12' ])}}" method="POST" class="form-horizontal">

or with the laravel form lib you can use something like this.. {!! Form::open(['route' => ['name.route.here', ['cd' => '14', 'song' => '12']], 'method' => 'post', 'class'=>'form-horizontal']) !!}

if Form is not working on the server you may need to install it with composer update

0

Thanks for your suggestion. I actually was using a named route as follows:

{!! Form::open(array('route' => array('venue.series.music.store',$venue,$series),'class' => 'form-horizontal', 'role' => 'form')) !!}

the html I posted above is what was generated by the Form package.

The problem though is that the form actually does work in some circumstances (provided I don't enter a valid url in the mp3 text field on the form. That's what I can't understand

0

bishopm said:

Thanks for your suggestion. I actually was using a named route as follows:

{!! Form::open(array('route' => array('venue.series.music.store',$venue,$series),'class' => 'form-horizontal', 'role' => 'form')) !!}

the html I posted above is what was generated by the Form package.

The problem though is that the form actually does work in some circumstances (provided I don't enter a valid url in the mp3 text field on the form. That's what I can't understand

im not sure of the convention here.. but is it ok to see a code or a url to the project to review further?

0

I have this problem too, did u find any solution?

0

No. My workaround at the moment is to insist on urls in the form xyz.com and then add the http:// part in the Controller. Frustrating, but I'm no closer to solving it

0

Sign in to participate in this thread!

Eventy

Your banner here too?

bishopm bishopm Joined 17 Jun 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.