Trying to Catalyse some prototype pages with form fields. My Catalyst controller does not seem to be getting the inputs from the form when it is submitted.
I have tried to reduce the template & controller down as far as I can and I am still getting this problem.
template is simply:
<body>
<form action="/minimal-testing" method="get">
<select id="select02">
<option value="cat1">cat1</option>
<option value="cat2">cat2</option>
</select>
<select id="select06">
<option value="1">1</option>
<option value="2">2</option>
</select>
<input type="submit" value="submit" title="submit" />
</form>
<p> Hello, params says: </p>
<p>
[% FOR param IN params ; param.key ; ' = ' ; param.value; END %]
</p>
</body>
Controller is:
sub minimal_testing :Path('minimal-testing') :Args(0) {
use Data::Dumper;
my ( $self, $c ) = #_;
$c->stash(params=>$c->req->params);
$c->stash(template => "dynamic/minimal-testing.tt");
$c->log->debug(Dumper($c->request->params));
}
When I browse to the form, pick from the select options, and submit, my debug log simply says
[debug] $VAR1 = {};
Obviously I am missing something so obvious I am just not seeing it... please enlighten me.
You're dead right. I suspect your Catalyst log should be giving you a clue what's going wrong here. The problem isn't with Catalyst.
Basically, it's malformed HTML - your form inputs each need a name parameter that can be passed back to the server in the POST.
<select id="select02" name="select02">
<option value="cat1">cat1</option>
<option value="cat2">cat2</option>
</select>
id is for CSS, name is for FORM processing.
Try that, and you should get logging like:
[11:31:28.499 16014:debug] Body Parameters are:
.-------------------+----------------------------------------.
| Parameter | Value |
+-------------------+----------------------------------------+
| select02 | cat1 |
| select06 | 2 |
'-------------------+----------------------------------------'
Hope that helps.
Related
I have a form which has 2 dropdowns questions.
Depending what the user answers, depends what will happen.
So for example
Are you human? The person answers yes and then another question show asking if they are employed, if they say yes to this then a sign up form will show.
If they say no to either question then some sorry cant sign you up text would show, with a form reset option ideally.
The first question seems to work fine, The issue is, it shows all messages for the second question which should be hidden until the value is selected and only one message should show.
Are you human?<br><select data-bind='value:thisSelect'>
<option value='none'>Select answer</option>
<option value='yes'>Yes</option>
<option value='no'>No</option>
</select>
<p data-bind="visible:thisSelect() === 'yes'">
Are you employed?<br>
<select data-bind='value:currentSelect'>
<option value='blank'>none</option>
<option value='form'>show form</option>
<option value='sorry'>Something else</option>
</select></p>
<br><br>
<p data-bind="visible:currentSelect() === 'blank'"> </p>
<p data-bind="visible:currentSelect() === 'form'">Hello, now display the sign up form</p>
<p data-bind="visible:currentSelect() === 'sorry'">Goodbye</p>
And my Knockout JS
var testing = {
thisSelect: ko.observable()
};
ko.applyBindings(testing);
var test = {
currentSelect: ko.observable()
};
ko.applyBindings(test);
My Js fiddle is here https://jsfiddle.net/Chazlie/sdpayfo7/12/
Another version I tried is here http://jsfiddle.net/Chazlie/2exnjm4t/24/ but this just replaces the message from the first question so is not what I was hoping it would do.
Thank you
For anyone else who is struggling with the same issue, I have solved this with the following, I believe the issue was that I was trying to call the bindings twice, instead of creating one variable and controlling it all there.
Are you human?<br><select data-bind="value: selectedChoice">
<option value="none">Select answer</option>
<option value="yes">Yes</option>
<option value="no">No</option>
</select>
<p data-bind="visible: selectedChoice() === 'yes'">
Are you employed?<br>
<select data-bind="value: currentSelect">
<option value="blank">none</option>
<option value="form">show form</option>
<option value="sorry">Something else</option>
</select></p>
<br><br>
<p data-bind="visible:currentSelect() === 'blank'"> </p>
<p data-bind="visible:currentSelect() === 'form'">Hello, now display the sign up form</p>
<p data-bind="visible:currentSelect() === 'sorry'">Goodbye</p>
<script>
var viewModel = {
selectedChoice: ko.observable("none"),
currentSelect: ko.observable("none")
};
ko.applyBindings(viewModel);
</script>
I want to fill a form select with informations of a table :"foreach"
i don't find a solution , someone can help me !i use cakephp 2.5.5 .
i want solution like that , but with cake php .
<select id="Select" name="section_id" class="form-control">
#foreach($sections as $section)
<option value="{{$section->id}}">{{$section->section_name}}</option>
#endforeach
</select>
Try this
First fetch data from database like this :
$result = $this->ModelName->findById('id');
$this->set('result',$result);
Then check in view file
<select id="Select" name="section_id" class="form-control">
#foreach($sections as $section)
<option <?php echo ($result['ModelName']['section_id'] == $section->id) ? 'selected="selected"' : '' ?> value="{{$section->id}}">{{$section->section_name}}</option>
#endforeach
</select>
Use Cakephp form helper to create select box so cake automatic display selected data like this
$this->From->select('ModelName.select_box_name',$sections);
So, I want to achieve a <select> like solution where a default value is equal to the value that is currently in the database, so the 'old value'.
1
I have this, where I loop a foreach to fill <option>.:
<select id="size" name="size" class="form-control">
#foreach ($sizes as $s)
<option value="{{ $s->value }}">{{ $s->name }}</option>
#endforeach
</select>
Now where I want to use this is an edit-form in laravel 5.2 where it fills in this form with the current values from the database for the selected user. My input fields with text fill in correctly but this select doesn't.
2
Working with Laravel forms I know this is possible to set the default value to S. But I don't know how to loop this is foreach...:
{{ Form::select('size', array('L' => 'Large', 'S' => 'Small'), 'S') }}
So I need to find a way to set default value with HTML-select tags while in a loop with values from my controller or find a way to loop in Laravel Forms.. Either is good, as long as it works
Don't know if this is what You are asking, but if You know current value, You can check it with if statement:
<select id="size" name="size" class="form-control">
#foreach ($sizes as $s)
#if ($s->value == $currentSize)
<option selected value="{{ $s->value }}">{{ $s->name }}</option>
#else
<option value="{{ $s->value }}">{{ $s->name }}</option>
#endif
#endforeach
</select>
What is the best way to construct a html5 datalist with mojolicious?
I looked for a tag helper but did not find a tag helper for constructing it.
Here is an example of a datalist:
<datalist id="frameworks">
<option value="MooTools">
<option value="Moobile">
<option value="Dojo Toolkit">
<option value="jQuery">
<option value="YUI">
</datalist>
The list is dynamic and is fetched from a db, so i cannot use a static html chunk.
There are similar tag helpers, e.g. for a <select> tag I can put into my template:
%= select_field country => [[Germany => 'de'], 'en']
which produces:
<select name="country">
<option value="de">Germany</option>
<option value="en">en</option>
</select>
but I couldn't find anything regarding a datalist in the default tag helpers.
It's been a while, but maybe will find it useful.
In the controller, you need to have an array with some items. Let's create it:
my #levelsArray = ();
for (my $i=0;$i<10;$i++){
push #levelsArray, "level00".$i;
}
After that, send it to the template:
get '/index' => sub {
my ( $mojo ) = #_;
$mojo -> stash ('levelsArray' => \#levelsArray);
$mojo -> render (template => 'index' );
};
and finally, render it using:
<%= select_field 'levelSelected' => [ #{ stash('levelsArray') }] %>
I'm not sure how this is mojolicious specific, but wouldn't simple html in your template would be enough:
<datalist id="frameworks">
<option value="MooTools">
<option value="Moobile">
<option value="Dojo Toolkit">
<option value="jQuery">
<option value="YUI">
</datalist>
<input type="text" list="frameworks" />
EDIT
Let me clarify, this wouldn't be static HTML in your template...you would fetch your data within controller and pass that data to template which would construct this kind of HTML with it's templating engine.
Before:
<input type='checkbox' name='killerFeature' id='killerFeature'
<%= param('killerFeature') ? ' checked' : ''%>
/>
Now:
<select name="killerFeature" id="killerFeature" class="select">
<option value="1">Enable</option>
<option value="0">Disable</option>
</select>
How do I insert the same checked (should be 'selected' now I guess?) condition in the select now?
This is a perl app, built using Mojolicious web framework.
Many thanks for your help!
Yes, the condition should be selected (selected="selected") but i belive you already figured that out from your other post :)
<select name="killerFeature" id="killerFeature" class="select">
<option value="1" selected="selected">Enable</option>
<option value="0">Disable</option>
</select>
Also from what i saw there inst a way to create the select like you can for the input as in the below example:
<%= input 'test', type => 'text' %>
So it would be something like:
<%== param('killerFeature') eq $my_var ? ' selected="selected"' : ''; %>
Ofc you would need to replace the above to your current variables and field names.
GL:)