Fail to submit a form in yii - yii

i am having a page with grid view and some checkbox fields init.
i added a submit button to it by adding echo CHtml::submitButton('Submit-form');
But, that button is not responding.
why so?
how i should submit this form?
my view page
my controller page

In your controller you have:
public function actionmyaction()
{
echo \'myaction reaced\';
var_dump($_POST);
}
You have to use camelcase with that, so actionMyaction() would probably do the trick.

Related

Closing nested CjuiDialog popup - Yii Framework

I am trying to develop the screen with nested popup (Popup inside another popup), Now am facing issues to close the inner popup and make visible the outer popup without redirecting to any page. how to achieve this ?
First popup has one grid and one new button, clicking on new button opens one more popup , here am uploading files and storing the details in DB while submitting the upload button, it should close the inner popup and focus should be in outer popup with updated grid details.
Please give any idea to achieve this ?
My 2nd Popup View Code,
<?php
echo CHtml::form('','post',array('enctype'=>'multipart/form-data'));
echo CHtml::activeFileField($model, 'name');
echo CHtml::button( 'Submit',array('submit' => array('baseContact/SaveAttachDocuments')));
echo CHtml::endForm();?>
Controller Action for 2nd Popup,
public function actionSaveAttachDocuments()
{
$model=new DocumentAttachmentModel();
$filename =CUploadedFile::getInstance($model,'name');
$model->type =pathinfo($filename, PATHINFO_EXTENSION);
$model->name =pathinfo($filename,PATHINFO_FILENAME);
$model->save();
/** Here i have to close the 2nd popup and update the grid in 1st popup **/
}
I guess you should close the inner popup by javascript (after client side validation), and then call the controller action for the outer popup again from the actionSaveAttachDocuments() method.

how to check validation error on submit button click in MVC?

I have one View and in which there 3 partial views are rendering.
And there is one Save button on the parent view(Index,in which the partial views are rendering).This Save button is common for all of the partial views.
My problem is, i am not getting the way in which i can check is there any model validation is firing on any of the partial views while click on Save button.
I used below check on Save button click :-
var status = $('form').valid();
But its not checking the validations of all the partial views.Its just checking the validations in that particular partial view in which i am clicking the Save button.
I got the solution for that.We can simply check the length of "input-validation-error" class on form's submit event.Just like that :-
if($(".input-validation-error").length == 0)
{
//there is no validation on form.
}else
{
//validation is firing somewhere.
}

How to open another page in HTML5 Builder

Sorry for my very simple question, I'am new to HTML5 Builder.
I'm developing a simple database editing application (to add or remove some advertisments on site, only for system administrator), and I want to make it using HTML5 builder (I hope, it will be fast and simple).
On button click on main page ("Add record" button), I need to open another page with data fields (advinfo.php).
How can I do it?
Thanks.
You just need to redirect to the target page. How to do so will depend on the language you want to use.
If you want to use the JavaScript OnClick event of the button:
function Button1JSClick($sender, $params)
{
?>
//begin js
window.location = "advinfo.php";
//end
<?php
}
If you want to use the PHP OnClick event (the standard event):
function Button2Click($sender, $params)
{
header("Location: advinfo.php");
}

Writing all model properties into view without having to do it per property

I have a page for listing items, and I have anchors in each of the items to edit it.
So when I click on the edit link, it will take me to the edit page, which have save button and cancel button.
I want it when I click the save button it'll take me to confirmation page which have OK and cancel button.
I know in asp.net mvc you can send model into the view by this
return View("Edit", model);
It is sensible to then write each of the model property like this in the view
#Html.EditorFor( model => model.name )
#Html.EditorFor( model => model.description )
//more properties here...
So that after I click the save button, I can have the model back in the controller
But after the edit page, I only need to view a question in the confirmation page do I have to write it manually like this
#Html.HiddenFor( model => model.name )
#Html.HiddenFor( model => model.description )
//more properties here...
Is there a one line hassle free function to do this in asp.net mvc?
You can use #Html.EditorForModel() helper. However this method will produce default UI elements like textboxes. You can provide a custom template that will produce hidden inputs.

enabling a submit button after an mvc post

I'm using .Net MVC 4.
I have two buttons on one View wrapped around two separate Html.BeginForm statements. The first one is visibile and the second one is not (it depends if the first button logic after the post is successfull).
How can I make visibile the second button after the first button pressed goes into the Controller method? The method basically says, I'm OK, now I can make visible the second button. I'm passing back a View. Is there a viewbag variable (or something of the sort) I can set that once I get back into the View, I can make that second button visisble?
The second button is just an input button with an Id value.
Is there a viewbag variable (or something of the sort) I can set that
once I get back into the View, I can make that second button visisble?
Yeah but since I am not a big fan of ViewBag I would suggest you adding a boolean property to your model and then set this property in the POST controller action.
[HttpPost]
public ActionResult SomeAction(MyViewModel model)
{
model.IsSecondButtonVisible = true;
return View(model);
}
and then inside the view:
#if (Model.IsSecondButtonVisible)
{
<input type="button" value="the second button" />
}
First Method: As explained above, but I am afraid, it will not work if for example you have a partial view and based on something there you want to show or hide something.
Second Method:Initial Page load, button is visible.
<input id='btnAdd' type='button' value='Add' style='display:block;'/>
Based on some action on page/partial view
<script>
function disableAdd() {
$('#btnAdd').hide();
}
</script>
*Please note, jquery will not be able to hide/show if you use visibility in style sheet.