CakePHP form in facebook validates on initial load - facebook

I have a simple form in CakePHP (version 2.4). If I open the url in the browser everything is OK, the form only validates after I click Submit for the first time. But if I put that same form inside Facebook app (as Page Tab) the same form validates right away and outputs all the errors before user even clicks Submit (ofcourse because all the required fields are empty on initial load).
My controler for the Form Add:
public function add($id = null) {
$this->set('title_for_layout', "Fb Form");
if (!empty($this->data)) {
$this->Application->create($this->data);
if ($this->Application->save()) {
$this->Application->saveField('fbapp_id', $id);
$this->Session->setFlash('Form saved');
$this->redirect(array('action' => 'add'));
} else {
$this->Session->setFlash('Form not saved');
}
}
}
Any help would be greatly appriciated so thnx in advance!

Related

bootstrap-validator check form

I am using 1000hz BootstrapValidator and after click on button (not submit because I need to stay on page without refresh) I want to check if form is correct.
I just can call $("#form2").validator('validate'); but I am not able to get return value.
I know about isDefaultPrevented but it is called after submit and I do not want submit.
$('#form').validator().on('submit', function (e) {
if (e.isDefaultPrevented()) {
// handle the invalid form...
} else {
// everything looks good!
}
})
Yeah one way is to change the from submit button type from submit to buttonand handle the validation via click function and count the length if any input field has error ($('#form2').validator('validate').has('.has-error').length) and handle it with if/else condition.
$(document).ready(function(){
$("#myButton").click(function() {
if ($('#form2').validator('validate').has('.has-error').length) {
alert('SOMETHING WRONG');
} else {
//$("#form2").submit();
alert('EVERYTHING IS GOOD');
}
});
});
Fiddle Example

CQ-Dialog page properties can not be stored from site admin but works from sidekick

The purpose of the following function is to allow the user to save the edited page properties in the CQ-Dialog even though if they invalid by clicking on the button save anyway:
PageProperties.showMsg = function(dialog, config, errorMessage) {
CQ.Ext.MessageBox.buttonText.ok = "save anyway";
CQ.Ext.Msg.show({
title : "Completeness check failed",
msg : errorMessage,
buttons: CQ.Ext.Msg.OKCANCEL,
fn : function(buttons) {
if(buttons == "ok") {
dialog.form.items.each(function(field) {
// clear fields with emptyText so emptyText is not submitted
if (field.emptyText && field.el && field.el.dom && field.el.dom.value == field.emptyText) {
field.setRawValue("");
}
});
var action = new CQ.form.SlingSubmitAction(dialog.form, config);
dialog.form.isValid = function() {
return true;
};
dialog.form.doAction(action);
dialog[dialog.closeAction]();
CQ.Util.reload();
}
}
});
};
This functions works fine from the sidekick. When I click on save anyway all current values of the page properites are stored regardless if they are valid or not. This does not work from the site admin. when I call the page properties of the same page from the site admin and try to save the page properties with invalid values by clicking on save anyway, this does not works (old values are stored and nothing changes).
I hope somebody can help. thank you
I found the solution. the problem was the function CQ.Util.reload(). It prevent storing the values

Winjs Application on Activated event

I have 2 pages - an authentication page and a content page.
After authentification is successful, I save this data: Winjs.Application.SessioState.mydata.
At the start (on launching) of the application, I want to detect if this data is not null so I can directly move to the content page. If it is null, I want to render the Authentication page.
Please help me, I don't know where to put the portion of code(in default.html or default.js).
BUT in my default.html I have this line:
<div id="contentHost" data-win-control="MyApp.PageControlNavigator"
data-win-options="{home: '/pages/home/home.html'}"></div>
(run the content page directly)
update this block of code in default.js in 'activated' event handler.
args.setPromise(WinJS.UI.processAll().then(function ()
{
if (nav.location)
{
nav.history.current.initialPlaceholder = true;
return nav.navigate(nav.location, nav.state);
} else if (!!app.sessioState.mydata)
{
nav.navigate('/pages/authpage/authpage.html', optionsIfAny);
}
else
{
return nav.navigate(Application.navigator.home);
}
}));

Submit extjs Form on button click

I am new for extjs.
I am having one store in which i am having some data coming from json file.
I have created a form.
i want to save new data in that store through form.
How can I create button and submit form on that button's click?
please let me know.
Thanks in advance
If you're using ExtJS 4 and your form is bound to a 'model' instance, then you get get a reference to your model in your buttons click handler and call:
model.save();
Which will send a post request to the url defined as the proxy on the model class.
Post your code and perhaps we can be some more direct help.
In the API of ExtJS is a good example on how to create a Ext.form.Panel with a button. When you click on this button the form gets submitted.
This example doesn't work because it doesn't submit to a page but it is very configurable.
Snippet of the button+handler:
buttons: [{
text: 'Submit',
handler: function() {
var form = this.up('form').getForm();
if (form.isValid()) {
form.submit({
url: '', //this is the url where the form gets submitted
success: function(form, action) {
Ext.Msg.alert('Success', action.result.msg);
},
failure: function(form, action) {
Ext.Msg.alert('Failed', action.result.msg);
}
});
}
}
}]

Staying on same page using Modal, Form Validation and Constant Contact Form Generator

I am a jQuery newbie and ma trying to use a modal to reveal a constant contact simple form generated by the form generator. I have applied jQuery.validate(), and the validation is working, but I don't know how to submit the form. If there is an action="signup/index.php" in the tag, i land on a new page.
The generated form uses action='signup/index.php' and this file calls for a new page location see file in Github. I commented those last lines out, but still am failing to make the form submit. I cannot see the new email in the Constant Contact email list.
This is my sumbmit handler
submitHandler: function() {
$('#signup').click(function(e) {
$.post('signup/index.php', $().serialize(), function(data) {
$('#output-div').html(data);
});
$('#form-message').fadeIn(300, function() {
$('#form-message').html('<p>Thank you for joining our list. Great offers coming soon.</p>')
});
$('#myModal').delay(1500).trigger('reveal:close');
});
}
solved it.
I had commented out the last several lines of the signup/index.php, including this line
if($postFields['request_type'] == 'ajax'){ $postFields["success_url"]=''; $postFields["failure_url"]=''; }
For some reason, that line is needed for form submittal success. Everything after that line is commented out, from
if ($return_code==201) {
to
</ol>
</p>'; }
}
and my jQuery is handling messages, errors and completion as such
submitHandler: function() {
$.post('/dev/rest/ccphp/signup/index.php', $("#ccsfg").serialize(), function(data) {
$('#results').html(data);
}).success(function() {
$('#ccsfg').html('<h4>Thank you for joining our list. Great offers coming soon.</h4>');
})
.error(function() {
$('#ccsfg').html('<h4>Oops! There was an error. Please try again. </h4>');
})
.complete(function() {
$('#myModal').delay(1500).trigger('reveal:close');
});
}