Laravel: Form buttons with names not showing in var_dump - php

I have 2 buttons with names neither of which show up in a var_dump($_POST) or print_r($_POST) on a form submit and I'm honestly confused as to why this would be happening. Is it a bug in Laravel or am I missing something? I'm using the latest Laravel version.
Here is my code:
{{ Form::open( array( 'id' => 'list-form', 'method' => 'POST', 'route' => 'user.admin.list' ) ) }}
{{ Form::button( 'Show List', array( 'type' => 'submit', 'name' => 'what', 'class' => 'btn btn-success' ) ) }}
{{ Form::button( 'Email List', array( 'type' => 'submit', 'name' => 'email_list', 'class' => 'btn btn-primary' ) ) }}
{{ Form::close() }}
Thank you for your help!
edit:
I've also just tried to do the following:
{{ Form::open( array( 'id' => 'list-form', 'method' => 'POST', 'route' => 'user.admin.list' ) ) }}
<input type="submit" value="Show List" name="show_list">
<input type="submit" value="Email List" name="email_list">
{{ Form::close() }}
But all I see in the output is just the form token and nothing else.

You are using Form::button(), but should be using Form::submit(). I just reproduced your form using two routes:
Route::any('form', ['as' => 'test', function()
{
return
// This one works
//
Form::open( array( 'id' => 'list-form', 'method' => 'POST', 'route' => 'user.admin.list' ) ) .
' <input type="submit" value="Show List" name="show_list">' .
'<input type="submit" value="Email List" name="email_list">' .
Form::close() .
// This one too
//
Form::open( array( 'id' => 'list-form', 'method' => 'POST', 'route' => 'user.admin.list' ) ) .
Form::submit( 'Show List', array( 'type' => 'submit', 'name' => 'show_list', 'class' => 'btn btn-success' ) ) .
Form::submit( 'Email List', array( 'type' => 'submit', 'name' => 'email_list', 'class' => 'btn btn-primary' ) ) .
Form::close() .
// This one doesn't
//
Form::open( array( 'id' => 'list-form', 'method' => 'POST', 'route' => 'user.admin.list' ) ) .
Form::button( 'Show List', array( 'type' => 'submit', 'name' => 'show_list', 'class' => 'btn btn-success' ) ) .
Form::button( 'Email List', array( 'type' => 'submit', 'name' => 'email_list', 'class' => 'btn btn-primary' ) ) .
Form::close() ;
}]);
Route::any('adminlist', ['as' => 'user.admin.list', function()
{
dd(Input::all());
}]);
In the first 2 you must receive something like:
array(2) {
["_token"] "TXlMuBczj4OmMEjOlkxusEhpUUZPBTqxQZHch2X2"
["email_list"] "Email List"
}
Also, you can use $_POST and $_GET in Laravel, but there's a better way:
Input::get('email_list');
If it doesn't work in your own code, you may have an HTML tag broken or a Javascript conflict. Try to debug it using your full raw HTML code.

A button is not part of a HTML form and is not send to the server.
Not really sure what you are trying to do here, with two buttons.
If you want a value in it, you will have to add that value to the $options array. But then again, what's the point of those multiple buttons?
From the spec:
The form element that the button is associated with (its form owner).
The value of the attribute must be the id attribute of a
element in the same document. If this attribute is not specified, the
element must be a descendant of a form element. This
attribute enables you to place elements anywhere within a
document, not just as descendants of their elements.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button

Related

how to submit a nested form using ajax post value with different url

i have two form that is i used nested forms created in laravel.here i want to submit nested form only.How to submit a nested form and how to sent the this form post values using ajax with different URl's. That is each will be submit with separate url.I have form like
{{ Form::model($property, array('url' => array('sampleurl'), 'class' => 'form-inline', 'id' => 'mainForm')) }}
{{ Form::model($property, array('url' => array('sampleurltwo'), 'class' => 'form-inline', 'id' => 'enquiryForm')) }}
{{ Form::select('country', array('' => '--Select--','india' => 'india','US' => 'US','singapore' => 'singapore','malesia' => 'malesia'), '', array('class' => 'textarea_field', 'required' => 'required')) }}
{{ Form::text('mobile', null, array('placeholder' => 'mobile', 'class' => 'text_field', 'required' => 'required')) }}
{{ Form::Submit('Connect Now',array('class' => 'connect connectNowButton', 'id' => 'connect', 'onclick' => 'sendVal()'))}}
{{ Form::close() }}
{{ Form::close() }}
Here is the post values i want to submit.

Send post parameteres via yii2 Html a()

I'm trying to send parameteres via yii\bootstrap\Html;
echo Html::a('Создать', ['/orders/order-create','freelancer_group'=>$_GET['freelancer_group']], ['class'=>'btn btn-lg btn-primary','data'=>['method' => 'post','derp'=>'herp'],]);
But when I click on it is still var_dump($_POST['derp']); is NULL. How can I post it? I 've found it here
echo Html::a('Создать',
['/orders/order-create', 'freelancer_group' => $_GET['freelancer_group']],
[
'class' => 'btn btn-lg btn-primary',
'data' => [
'method' => 'post',
'params' => ['derp' => 'herp'], // <- extra level
],
]
);

YII how to set a custom delete button for ButtonColumn?

I would like to change the custom implementation of the delete button in gridview for buttoncolumn. I want to add a custom icon and a custom css class to the delete button. When i add the option parameter it dose not work any more. So i decided to create a custom link to the delete function but it gives me a 400 error when i click on it.
Any ideas ?
Below code
array(
'header' => __('Manage'),
'class' => 'booster.widgets.TbButtonColumn',
// 'htmlOptions'=>array('style'=>'white-space: nowrap;'),
'template' => '{approve} {details} {erase}',
'htmlOptions' => array('style' => 'white-space: nowrap;'),
'buttons' => array(
'approve' => array(
'label'=>__('Approve'),
'icon'=>'pencil',
// 'options' => array('target' => '_blank'),
'url' => 'Yii::app()->createUrl(\'tours/updateadmin/\'. $data->tour_id)',
'options' => array(
'class' => 'btn btn-small btn-info',
),
),
'details' => array(
'label'=>__('View Details'),
'icon'=>'check',
'url' => 'Yii::app()->createUrl(\'tours/view/\'. $data->tour_id)',
'options' => array(
'class' => 'btn btn-small btn-info',)
// 'options' => array('target' => '_blank'),
// 'url' => 'Yii::app()->createUrl(\'tours/updateadmin/\'. $data->tour_id)',
),
'erase' => array(
'label'=>__('Delete'),
'icon'=>'trash',
'url'=>'CController::createUrl("/tours/delete", array("id"=>$data->tour_id))',
'options' => array(
'class' => 'btn btn-small btn-info',)
),
),
),
What's your 400 error details? I think the problem is your link. Try to remove first / from your link:
'erase' => array(
'label'=>__('Delete'),
'url'=>'Yii::app()->createUrl("tours/delete", array("id"=>$data->tour_id))',
'options' => array(
'class' => 'btn btn-small btn-info'
)
),
),
If the problem did not resolve, you should edit your question and add error details for better helping.
Also, note that CButtonColumn#buttons does not have icon field. Here is a link that shows possible options for CButtonColumn#buttons . So you should remove icon field from all of your buttons.

Disabled button em CakePHP

[below translated from translate.google.com]
I'm looking for the syntax of how to make a button disabled in CakePHP and I can not get a result; My application need to first save a field for a button to finish the whole process after another button. The first button is a submit and redirects to the same page. The second button performs a function of the controller and go to the next process. I want to prevent the user to go to the next procedure without saving the first; I already have a variable that defines whether it is safe or not, just do not know how to make the Finish button is disabled;
Button code:
echo $this->Html->link(
$this->Html->tag('span', '', array('class' => 'glyphicon glyphicon-ok')) . " Finalizar",
array('controller' => 'Questoes','action' => 'limparSession'),
array('role' => 'button', 'class' => 'btn btn-success', 'escape' => false)
);
Add the disabled class to your button:
<?php
echo $this->Html->link(
$this->Html->tag('span', '', array('class' => 'glyphicon glyphicon-ok')) . " Finalizar",
array(
'controller' => 'Questoes',
'action' => 'limparSession'
),
array(
'role' => 'button',
'class' => 'btn btn-success disabled',
'escape' => false
)
);
?>
This is a bootstrap feature related to the given class.
If you want to do it without bootstrap:
<?php
echo $this->Html->link(
$this->Html->tag('span', '', array('class' => 'glyphicon glyphicon-ok')) . " Finalizar",
array(
'controller' => 'Questoes',
'action' => 'limparSession'
),
array(
'role' => 'button',
'class' => 'btn btn-success',
'disabled' => 'disabled',
'escape' => false
)
);
?>
echo $this->Form->button(
$this->Html->tag('span', '', array('class' => 'glyphicon glyphicon-ok'))." Finalizar",
array('type' => 'submit','onclick' => 'this.disabled=true;return true;',
'class' => 'btn disabled', 'escape' => false)
);

Multiple Submit buttons in cakephp form

I have a form in a cakephp view which saves well with a single button, here is the code in the view book_form.ctp
echo $this->Form->create
(
'Book',
array
(
'url' => array
(
'controller' => 'Books',
'action' => 'save_record'
),
'class' => 'span12 the_ajaxform',
'inputDefaults' => array
(
'label' => false,
'error' => false
)
)
);
.
.
// form fields
.
.
$options =array(
'label' => __('Save'),
'class' => 'btn btn-primary',
'id'=>'saveform'
);
echo $this->Form->end($options);
.
.
This works perfect! Now i wanted to add two buttons on that form and this is what i did
$options =array(array(
'label' => __('Save & Close'),
'class' => 'btn btn-primary',
'id'=>'saveform'
),
array(
'label' => __('Save & Create New'),
'class' => 'btn btn-primary',
'id'=>'saveformnew'
)
array(
'label' => __('Cancel'),
'class' => 'btn btn-primary',
'id'=>'formcancel'
));
echo $this->Form->end($options);
But this only brings one button which wont even submit the form,where am i going wrong?
and can each button call a different method in the controller?
Thanks in advance
If you set the name of the submit button, it will have that as a key in the post data, so you can redirect using that info at the start of your action. e.g.
<?php echo $this->Form->submit('btn1value', array('name'=>'btn1'))?>
<?php echo $this->Form->submit('btn2balue', array('name'=>'btn2'))?>
clicking the first button will give post data like:
array(
[btn1] => btn1value
[YourModel] => array(...)
)
Which makes it easy to do something like:
if (isset($this->request->data['btn1'])) {
// btn1 was clicked
} else if (isset($this->request->data['btn2'])) {
// btn2 was clicked
}
I am not sure whether it is "Technically Correct", HTML4, 5 compatible or not etc. but I have always done it something like this, without any problem so far:
<?php echo $this->Form->submit('Delete it', array('name'=>'User[formaction]')); ?>
<?php echo $this->Form->submit('Undelete Selected', array('name'=>'User[formaction]')); ?>
<?php echo $this->Form->submit('Purge Selected', array('name'=>'User[formaction]')); ?>
where "User" is the model name.
Usually one form can have just one action
this lmnitation is no longer true in HTML5 where you can set the form action for every button
so: the following code works only for HTML5 browsers
echo $this->Form->button(
'Your Action Description Here',
array(
'type' => 'submit',
'formaction' => 'yourActionHere' //
)
);
Try this, This is easy to do.
<div class="submit">
<?php echo $this->Form->submit(__('Submit', true), array('name' => 'ok', 'div' => false)); ?>
<?php echo $this->Form->button('Cancel', array('type' => 'button'));?>
Try using the FormHelper's button function to create the submit button and the other buttons and just call end after that without any options. This will output the buttons and end your form for you.
See: FormHelper::button
e.g.:
echo $this->Form->button('Save & Close', array('type' => 'submit'));
echo $this->Form->button('Save & Create New', array('type' => 'button'));
echo $this->Form->button('Cancel', array('type' => 'reset'));

Categories