popup contact form with validation - php

I would like to create popup contact form with validation like i did here http://89.212.111.174/delovtujini.si and click “VPIS V BAZO”.
You will get popup where you can fill contact form. How can i do this with CI? Here on this example i do everything in the same html page. In CI i try to create new controller for contat form but i dno’t know how to open the window. I also try to use http://fancyapps.com/fancybox/ I try. but none solution works.
Can someone explain me how to do? Maybe is better to use https://github.com/EllisLab/CodeIgniter/wiki/Ajax-Framework-For-CodeIgniter
Thx

there are 3 ways to trackle your issue.
1) Use custom inline lightbox like what is done on
http://89.212.111.174/delovtujini.si
First post the form back to the same page like below:
public function sign_up()
{
// Setup form validation
$this->form_validation->set_rules(array(
//...do stuff...
));
// Run form validation
if ($this->form_validation->run())
{
//...do stuff...
redirect('');
}
// Load view
$this->load->view('my_form');
}
In the view when you detect a POST you must have javascript
to "open" the lightbox on page load since it won't be display by default (i.e. when you load the page normally the lightbox is "closed" and it is "opened" only when the button is clicked.)
2) Use a iframe lightbox
create the form on a separate CI controller/view and display in within an iframe when the button is clicked.
when the form is submitted you can then call javascript to close the lightbox.
3) Use ajax
both inline and iframe lightbox can work with an ajax form
the idea the same as using an iframe lightbox. Once the form is submitted via ajax, use javascript to close the lightbox.

Related

cakephp 3.0 submit part of form

is there way to submit part of a form without refreshing the whole page? Basically, I want to add a search box with a button in the view, when I click this button it runs a function / action in the controller. My apology if this has been asked before but I've searched for couple of hours and I couldn't understand the ones I came across.
This page will help you learn about how CakePHP handles AJAX:
http://book.cakephp.org/3.0/en/controllers/components/request-handling.html
Now, be aware the default behavior of a form is submit itself to a page or to the same page (reloads). If you want to prevent the form from submitting (reload the page) have something like this:
<form onsubmit = myFunc() >
..
function myFunc(){
//Send the ajax request. You can use JQuery
//Handle response
return false; //This will prevent the page reload...
}

In Gravity forms, form is disappeared after successfully submitting the form

By using gravity form I have generated a contact form. When I submit the form, the form disappears and a success message is shown.
What I want, is that the form stays, and a success message is shown below the form. Can anyone help me solve this..
Enable AJAX
Checking this option will enable your form to be submitted via AJAX. Submitting the form via AJAX allows the form to be submitted without requiring a page refresh.
https://www.gravityhelp.com/documentation/article/embedding-a-form/
You can enable it in the settings if you go into Wordpress admin -> form -> settings
You can use this filter
add_filter('gform_get_form_filter', function($form_string, $form) {
$form_string = str_replace( "replaceWith", "append", $form_string );
return $form_string;
}, 10, 2);
$form_string contains javascript which is executed after form submit.
You're replacing the javascript function replaceWith with append.
Works perfect for me.
This answer responds to Adrian's comment on Svetlozar's answer.
To disable the Ajax realoader thing just go to posts, find the form from there and you can disable it in the settings on the right side in advanced options.
Alternatively I am thinking just find the CSS for that reloader and use display:none in CSS.

Redirect Lightbox after form submission

I'm using Fancybox 2 to display some forms on my website. The form comes through from an external page into an IFrame to let the user post a message, kind of like twitter does. However I want the user to be re-directed after the form has been posted. So they post the form to a database, the Fancybox window shuts down and then they are redirected to the posts page where they see their newly posted message. Is there a way of doing this succesfully?
You can try this:
<script>
if(data == 1){
//window.location.replace("dashboard.php"); //will open the page in the fancybox
parent.$.fancybox.close(); //will close the fancybox
//parent.window.location.replace( your_url_here ); //your redirecting URL here
parent.window.location.href = 'dashboard.php'; //your redirecting URL here
}
</script>
I would recommend you to use a real form rather than a post action. You are not really using form submission otherwise, but just a POST request.
If you do that, you could use the target="_top" inside the <form tag and submit the results using the submit function of jQuery.

open new window / tab after form submit using an drupal javascript invoke

yes this question is asked some times. but I can't find an answer for my problem.
I've posted my question here because it is more php / javascript related then drupal I guess.
So basically I have a form that is validated and on the submit part I have a ( drupal hook ) function in php where I can add / modify code.
This function catches the form fields and stores them in the database.
This means that the fields are filled correctly so I want to implement something here that opens a new tab or window for the user without closing the current one.
So I know you can't call javascript from php to use something like window.open() but is there anyway I can make it so that this window.open() is called?
I'm also open for a bit different approach if you have any.
You can use an anchor element to both submit a form and open a new window:
<script>
function submitMyForm()
{
// Validate form fields here
// ...
// If form is valid, submit it
myForm.submit();
}
</script>
Submit Form

Zend Framework - using jquery dialog for popup form in a Zend controller/action

I am editing to try to put my primary question at the beginning of this post:
1) I am sitting at my customers/preferences page updating info in the form
2) I want to add a widget to my list of available widgets, so I need to open the widgets/addWidget page/form to add a new widget (note I am still working in my current customers/preferences page/form, so I need to continue with this page after adding a new widget in the widgets/addWidget page/form.
3) I select a link to go to widgets/addWidget, and I have jQuery dialog open this link in a dialog with the addWidget form and submit button
4) after adding a newWidget in the dialog popup form, I want to submit the newWidget (the code for addWidget is in the widgets/addWidget controller/action, not in the customers/preferences action)
Problem: the addWidget form action goes to widgets/addWidget, so when I submit the addWidget form in the dialog, it takes me away from my current customers/preferences page
Question 1) what is the proper/best way given this scenario to popup a form in another controller/action to submit that form, but then resume my current controller/action?
Question 2) should I move all of my form and code from the widgets/addWidget controller action into my existing customers/preferences action? (that seems to be the wrong approach)
I have researched jQuery documentation, Zend documentation, and searched other threads with trusty Google and stackoverflow, but I am still struggling to figure out the right way to get this to work with Zend Framework and popup forms such as jQuery dialog.
I have a working Zend action/controller that using a Zend Form and view to display and process my form. I have also been able to use jQuery dialog to popup a window when I click the link to that controller/action.
My issue is with the proper way to get the dialog to display the form and still be able to submit and process the page. If I only load the #content tag in the dialog the form and submit button appear in the dialog box, but the submit button no longer works. If I let the dialog open the full page (not just the #content) now the form will process properly, but the form submit is set to go to my action page for processing, so the form submits and takes me away from the original page and to the real controller/action page instead.
In my customerController I have a preferencesAction where a customer can choose a widget from a list of widgets. When the customer needs to add a new widget to the list, I want to open the addWidgetAction from the WidgetsController in a popup form. I want to add the widget in the popup form, submit the form to the addWidgetAction, and come back to the customer/preferences page I was already working in (with the newly added widget available in my list to select from).
//CustomerController
public function preferencesAction(){
//this is where I click a link to /widgets/addWidget and use jQuery dialog for form
}
//Customer preferences.phtml
<script>
$(document).ready(function() {
$('#add-link').each(function() {
var $link = $(this);
var $dialog = $('<div></div>')
.load($link.attr('href'))
.dialog({
autoOpen: false,
title: $link.attr('title'),
width: 600,
height: 500,
buttons: {
"Add Widget": function(){
$("#AddWidget").submit();
},
"Cancel": function(){
$(this).dialog("close");
}
}
});
$link.click(function() {
$dialog.dialog('open');
return false;
});
});
});
</script>
<a id="add-link" href='<?php echo $this->url(array('controller' => 'widgets',
'action' => 'addwidget')); ?>'>Add a Widget...</a>
//WidgetsController
public function addWidgetAction(){
// display form to add widget
// process form, validate, add to widgets table
$baseUrl = $this->getRequest()->getBasePath();
$action = $baseUrl . '/widgets/addWidget';
$form = new Form_Widget();
$form->setName('Add Widge')
->setAction($action);
}
I need to understand how to get the dialog to load my Zend action page for form processing, but without requiring the entire layout with header, footer, etc. I also need to understand how to process the form in the dialog popup without moving away from my original page where the popup was linked from.
Thank you for your assistance!
Well, I am not sure if i understand your question but you can try this
You can load your form in UI dialog box, to disable layout do this on you can do this
public function addwidgetAction(){
$this->_helper->layout()->disableLayout();
//just diable layout and do eveything normal
}
on your preferences.phtml file load the content of url baseurl/contrller/addwidget to jquery modal dialog
UPDATE
One way is use a jqueryplugin fancybox (external src) check the forgot password link
The other way is to use ajax
UPDATE
Well now i read your question well, though don't understand so clearly, i understand that you are trying to do something that is quite ambitious. And you cannot achieve through normal load method. You need to use ajax
I have to admit that I don't like jquery ui modal dialog so i don't know much about it, and i usually use jquery fancy box where it would give me an ability to load external page. Maybe you can do this through jquery ui modal dialog box.
I guess the problem that you are facing right now is you open a dialog box, you get the form in dialog, and you submit the form, it sends the normal post request, so dialog is reloaded, that's what happens in the link i have above, just click on forgot password link
Well there's solution for that too, the solution is ajax, and i hope you are quite familiar with it. you send ajax request and get response back, and depending on your response, you can exit dialog box as well update the the parent (preferences controller page) but that is quite ..... I tried to so same with few months back, but not with zf, i don't know how much i accomplished but it sure gave me a nasty headache

Categories