Passing a url through an html form.

Published 1 week ago by samuelgrant

Is it possible to pass a url value through a forum input and sent it to a controller without the data being lost.

For example I would like to be able to pass data through in this format and then be able to work with the numbers on the other side. At the moment, I only get *test as the result.

<url=info:22852:41411;1:31942;1:41415;4:21096;1:41200;1:19282;1:41459;2:33844;4:41493;1:31798;3:4347;2:40560;4:40556;4:40558;3:29001;2:28999;1:16273;3947::>*test

Best Answer (As Selected By samuelgrant)
Snapey

Sorry guys I don't get it... a regular form input or text area should work fine.

Why would it need to be serialised?

by the way, label has a typo and a text area does not have a type option but fundamentally I can't see anything wrong with the form.

Dump the request in the controller to check what is recieved dd($request->all())

robrogers3

show us a snippet of html, what's the form field name?

samuelgrant
{!! Form::open(['route' => 'sendDNA', 'method' => 'POST', 'enctype' => 'application/x-www-form-urlencoded', 'style' => 'padding:10px']) !!}
    <div class="form-group">
        <lable>Fit DNA:</lable>
        <textarea class="form-control" type="url" rows="4" name="shipDNA" placeholder="<url=fitting:22852:41411;1:31942;1:41415;4:21096;1:41200;1:19282;1:41459;2:33844;4:41493;1:31798;3:4347;2:40560;4:40556;4:40558;3:29001;2:28999;1:16273;3947::>*test</url>" style="resize:none;"></textarea>
    </div>
    <button class="btn btn-primary btn-sm" type="submit">Save</button>
{!! Form::close() !!}```
Drfraker

Put it in a hidden field and serialize it. The unserialize it in your controller. Why are you adding this data to a placeholder? Do you want to view it in the textarea?

mushood
mushood
1 week ago (60,800 XP)

if you want to pass it to the server, it should be "value" instead of "placeholder"

samuelgrant

The placeholder is just their to give an example, could you give me a code snippt example on how the serialize would work, this is not something I have had a chance to work with as of yet.

Thanks for your feedback.

RamjithAp

First in your form serialize the data and keep it in hidden field

{!! Form::open(['route' => 'sendDNA', 'method' => 'POST', 'enctype' => 'application/x-www-form-urlencoded', 'style' => 'padding:10px']) !!}
    <div class="form-group">
   <lable>Fit DNA:</lable>
    <input type="hidden" class="form-control" type="url" rows="4" name="shipDNA" value="<?php echo serialize("<url=fitting:22852:41411;1:31942;1:41415;4:21096;1:41200;1:19282;1:41459;2:33844;4:41493;1:31798;3:4347;2:40560;4:40556;4:40558;3:29001;2:28999;1:16273;3947::>*test</url>"); ?>" style="resize:none;"></textarea>
    </div>
    <button class="btn btn-primary btn-sm" type="submit">Save</button>
{!! Form::close() !!}

And then in your controller

$url = unserialize($request->input('shipDNA'));
samuelgrant

Thank-you, so much. I will test it later tonight.

Snapey
Snapey
1 week ago (678,595 XP)

Sorry guys I don't get it... a regular form input or text area should work fine.

Why would it need to be serialised?

by the way, label has a typo and a text area does not have a type option but fundamentally I can't see anything wrong with the form.

Dump the request in the controller to check what is recieved dd($request->all())

samuelgrant

Thanks Snapey, thanks for pointing out the type in the text are, not quite sure what that was doing there.

For clarification sake the placeholder is there to display demo data, the actual data will be different and entered by a user.

It looks like the issue I was having was when a user entered a time stamp at the beginning of the input. [02:21:22] this time stamp was turning it into an array of data and causing issues.

Thanks for the help!

Snapey
Snapey
6 days ago (678,595 XP)

ok, but does not make any sense. Text area just captures a string. html and array characters are irrelevant inside the form element. It just depends what you do with the field afterwards.

Please sign in or create an account to participate in this conversation.