My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
PassingFormValues  
Explanation on passing form variables values to MB pages
Help, Deprecated
Updated Dec 15, 2009 by andrej.o...@gmail.com

Introduction

For example we have the following form on one MB page:

<form action="yoururl.php" method="get" id="myform" onsubmit="return false">
<fieldset>
<label for="name">
Your name
</label>
<input type="text" size="30" id="name" name="name">
</input>


<label for="email">
Email to
</label>
<input type="text" size="30" id="email" name="email">
</input>


</fieldset>
<input type="submit" value="Submit" onclick="Modalbox.show('yoururl.php', {title: 'Sending status', params: *Form.serialize('myform')* }); return false;">
</input>
</form>

and then in youurl.php we're doing the following:

<?php

$name = $GET['name']; $email = $GET['email'];
?>

<?php echo $name ?>, your message sent!

to show the sender name.

That's all!

Details

See the working example here: http://okonet.ru/projects/modalbox/ Please note: http://prototypejs.org/api/form/serialize

Comment by bart...@kabelfoon.nl, Aug 2, 2007

Verry cool, but have to read a lot to get it i quess;) iI think it's wurth that!

Comment by thomas.h...@gmail.com, Aug 17, 2007

Is there a way to change the method from GET to POST? I tried:

{params: Form.serialize('myform'), method:post}

Doesn't work...

Comment by thomas.h...@gmail.com, Aug 17, 2007

Is there a way to change the method from GET to POST? I tried:

params: Form.serialize('myform'), method:post

Doesn't work...

Comment by thomas.h...@gmail.com, Aug 17, 2007

Is there a way to change the method from GET to POST? I tried:

    params: ..., method:post

Doesn't work...

Comment by alaat...@gmail.com, Aug 27, 2007

I think the order of the "show(" argument's are given regarding the previous release. The url of the next modalbox should be the the first one.

Comment by green.ta...@gmail.com, Aug 31, 2007

try

method: 'post'

Comment by green.ta...@gmail.com, Aug 31, 2007

any idea how to post multipart MIME? our form has a field for uploading a picture but the MB requests are url-encoded. Any help would be great.

TIA, -gt

Comment by juanf...@gmail.com, Sep 6, 2007

It doesn't work to me. Is there any update that breaks it? I get to yoururl.php but i can't get the params. It also tried with : $('myform').serialize(true) instead of : Form.serialize('myform') I just can't make it work!!! Any help there? regards, juanfra

Comment by juanf...@gmail.com, Sep 7, 2007

the way to call it is Modalbox.show('yoururl.php', {params: Form.serialize('myform') }); return false;

Comment by mestoca...@gmail.com, Oct 8, 2007

Not Working

Comment by project member andrej.o...@gmail.com, Oct 15, 2007

It's working on the demo page here: http://wildbit.com/labs/modalbox/

Comment by donwil...@gmail.com, Oct 20, 2007

Corrected Text

and then in yoururl.php we're doing the following:

<?php

    $name = $_GET['name']; $email = $_GET['email']; 

?> <h1><?php echo $name ?>, your message sent!</h1>
Comment by ste...@gmail.com, Nov 22, 2007

Could use www.gettopost.com/gettopost.html to do the GET to POST conversion?

Comment by rober...@gmail.com, Dec 13, 2007

I can get $POST's to work for <input type="text"> but CAN'T for <input type="file"> Is there a way to do this? Is there a param spot for enctype="multipart/form-data"? TIA

Comment by jted.es...@gmail.com, Jan 10, 2008

I was having this problem with a form. What fixed things for me was to add an "id" tag to the form declaration.

Comment by msdark...@gmail.com, Jan 17, 2008

(sorry for my english, but i speak spanish) in this example the form is put into a modalbox o a normal window????

i trie tu put a form into modalbox to send data to the same modalbox (or another)... this example works for send data to the normal window to modalbox, but i can't send data to the form on modalbox to modalbox... how can i get it??

Comment by tactical...@gmail.com, Jan 17, 2008

$GET works, but is there a way to automatically close the the box after success? (I'm guessing maybe DOM?)

Comment by juraji...@gmail.com, Jan 19, 2008

Hello, i need to send my data via $POST, what i need to change and where?

thanks a lot

Comment by ni...@deviantart.com, Apr 1, 2008

and what about instead of the action being a 'yoururl.php' it is a <?php echo $somevariable ?>, how would you make the messages contained within that variable appear in the next modalbox?

Comment by sukhvind...@gmail.com, Apr 29, 2008

I am opening a LOGIN textbox and password field in the modal window(Actually my PHP page). After submitting of the data using POST, i want to display WELCOME page in same modal window...

Is it possible.. ?

Comment by paul.bo...@gmail.com, May 3, 2008

For the POST version it works I do that : <form id="formulaire" action="url.php" method="post" onsubmit="return false;"> ... <input type="submit" title="TITRE" value="Show" onclick="Modalbox.show('url.php', {title: this.title, method: 'post', params:Form.serialize('formulaire'), overlayClose: true }); return false;" class="formulaire" /> </form>

It works fine :)

Comment by dina...@gmail.com, Jun 4, 2008

Yeah this script from paul with POST worked for me too!!! Thx really much paul!!!

Comment by walams...@gmail.com, Jun 23, 2008

i got problem too with <input type="file"> Is there a way to do this? Is there a param spot for enctype="multipart/form-data"?

Comment by Benjamin...@gmail.com, Jul 1, 2008

to answer a few of your questions re file uploads:

This cannot be done because modalbox uses Prototype's Ajax.Request function which does not allow uploads.

There is another solution though: look into SwfUpload? - http://swfupload.org/

Comment by mikestr...@gmail.com, Jul 22, 2008

I am struggling with the wizard function. I have a form in the modalbox. When I click the button, I want to pass the variables of the form to itself and then repaint the modalbox with the changes. I am running PHP on the back side. It seems like this should be possible, but when calling ...

<button type="button" onclick="Modalbox.show('Making changes', 'sameAsOriginalPage.php', {width: 600, height:650}); return false;">&lt;&lt; Remove selected users from group</button>

The box shrinks and just stays there. What am I doing wrong?

Mike

Comment by arnelcel...@gmail.com, Nov 27, 2008

dynamic content/form elements is not included when submitting the form using modalbox

Comment by waz...@gmail.com, Dec 22, 2008

I am trying to submit a contact form. I have tried a number of things, but I am not able to get the form to submit (email). It will either submit the form, or continue to the yoururl.php, but I cannot get it to do both submit and move to the yoururl.php page.

Any help would be great.

Here is the code I am using for the form:

<form id="form" name="form" method="post" action="forms/process.php"> <label>Name <span class="small">Add your name</span> </label> <input type="text" name="Name" id="name" />

<label>Email <span class="small">Add a valid address</span> </label> <input type="text" name="Email" id="email" />

<label>Phone <span class="small">Min. size 10 chars</span> </label> <input type="text" name="Phone" id="phone" />

<label>Message <span class="small">Leave a message</span> </label> <textarea name="Message" class="mytextarea" id="message"></textarea>

<button type="button" value="Submit" onclick="Modalbox.show('forms/yoururl.php', {title: 'Sending status', params: Form.serialize('myform') }); return false;" />Submit</button>

Comment by wenm...@gmail.com, Apr 12, 2009

good stuff. thanks!

Comment by saucisso...@gmail.com, Apr 27, 2009

I had a prolbem using it, so I tired this :

Modalbox.show(this.href, {title: this.title, width: 600, method: 'post', params: inscriptionCB.serialize(), overlayClose: true }); return false;

Note that I used inscriptionCB.serialize() instead of Form.serialize('inscriptionCB') (inscriptionCB is the name of my form).

Hoping it will help somebody.

Comment by saucisso...@gmail.com, Apr 28, 2009

Oh sorry, this tricks works onl with Firefox. Finally I used : Modalbox.show('inscriptionCB_commentaire.php',{title: 'Commentaire envoyé', width:600, method: 'post', params: Form.serialize(inscriptionCB_ajoutCommentaire), overlayClose: true})

Note the "Form.serialize(inscriptionCB_ajoutCommentaire)"

Comment by alisveri...@gmail.com, Jun 12, 2009

thaks alot

Comment by judemwe...@gmail.com, Jul 20, 2009

hi, i have a select field in my modal box. but it is a form that should be filled and updates the database. Any idea on how to do this. the select is not being fetched

Comment by flo...@gmail.com, Sep 1, 2009

Value of FCKeditor don't work! :/

Comment by sfcarva...@gmail.com, Nov 19, 2009

Yep the POST Method works ...

<input type="submit" value="Visualizar o relatório"

onclick="Modalbox.show('empregado_relat.php', {title: 'Relatório de Empregados', method: 'post', params: Form.serialize('empregado'), overlayClose: true, width: 600, height: 600}); return false;" />

Tks a lot!

Comment by jadhavkapil, Dec 17, 2009

Does anyone know how to do form validation on modal box? I tried many things but nothing worked, I see in the demo email validation is in place. Please please please help...

Comment by Yaj...@gmail.com, Mar 11, 2010

Hi everyone... i was the same problem... and test, and test, and teste, and test... and teste angain, and again, and again.... in the end i think to do work. (sorry by my english. I speak only Spanish and portugues )

My solutions:

3 php pages (i work whith php)... so go head.
  • index.php
  • formSend.php
  • formRecive.php

index.php

<a href="formSend.php" title="Titulo da barra" onclick="Modalbox.show(this.href, {title: this.title, width: 600}); return false;"> OPEN </a>

formSend.php

<form id="form" name="form" method="post" action=""> 
  <label>Name </label> 
  	<input type="text" name="Name"/>
  <label>Message </label> 
  	<textarea name="Message"></textarea>
  <button type="button" value="Submit" onclick="Modalbox.show('formRecive.php', {title: 'Sending status', params: Form.serialize('form') }); return false;" />Submit</button>
</form> 

formRecive.php

<h1>Recive all $vars from formSend.php</h1>
<P>
<?php
$var1 = $_GET['Name'];
$var2 = $_GET['Message'];

echo $var1;
echo '<br/>';
echo $var2;
?>
</P>

--- if anyone get nice results, please write me. ---

Comment by gregoire...@gmail.com, Apr 26, 2010

Here is a working procedure to really use a FCKeditor inside a Modalbox :

I will use 2 files. One from which the modalbox is defined, and one wich be called inside the Modalbox, and will contain the FCKEditor.

First call of the Modalbox

The Modalbox is called with a button where i put a onclick instruction :

onclick="Modalbox.show('solutions.php', {title: this.title, method: 'POST', params: {id: '<? echo $id; ?>'} }); return false;"

So the Modalbox is created, with solution.php called inside, and the 'id' value sended to by POST.

Integration of FCKEditor inside of the modalbox

In solution.php there is a form who send the datas to itself.

<form action="#" method="POST" name="solution-form" id="solution-form" accept-charset="utf-8" onsubmit="Modalbox.show('solutions.php', {title: 'FCKEditor integration', width: 500, params:Form.serialize('solution-form'),overlayClose: true }); return false;">

params: Form.serialize('form') is supposed to get all input values of the form.

I created my FCKEditor in the PHP way:

<?php
$oFCKeditor = new FCKeditor('solution') ;
$oFCKeditor->BasePath = '/fckeditor/' ;
$oFCKeditor->Value = $_POST['solution'] ;
$oFCKeditor->Create() ;
?>

as described here: http://docs.cksource.com/FCKeditor_2.x/Developers_Guide/Integration/PHP

If you create a FCKEditor called 'solution', it will create an iframe with the rich editor, and an hidden input with this name:

<input id="solution" name="solution" value="" style="display: none;" type="hidden">

The FCKEditor code is supposed to attribute the content of the iframe to this hidden input, but there is a conflict between FCKEditor and Modalbox codes so this hidden input can not take value of the FCKEditor iframe.

As a consequence, params: Form.serialize('form') of the Modalbox is unable to get the value of the FCKEditor because the hidden input remains empty, and you have an error saying ='FCK is not defined in fckeditorcode_gecko.js on line 31'.

So we will force the value of the hidden field in javascript before submit the form, using the FCKEditor API.

So in my form, on the submit button i add this code (in my case the hidden field is called 'solution':

onclick="javascript:document.getElementById('solution').value=FCKeditorAPI.GetInstance('solution').GetXHTML();"

Source (in french): http://www.tayo.fr/fckeditor-ajax-recuperer-texte-astuce.php

So when I click on submit, the FCKEditor API put the content of the FCKEditor iframe as a value of the hidden input 'solution' created by the FCKEditor, and on this allow params: Form.serialize('form') to get it correctly.

On the php side i can get this value with a classical :

$solution=*_POST['solution'];

I hope that my explanations are clear (french speaking here), and that they can help.

Comment by artle...@gmail.com, Oct 23, 2011

Well I have tried each and every suggestion. I think the developer ought to get a solution and post it with which browsers he has tested it on. I can't get it to work and by the number of other comments I'm not alone. But some people have gotten it to work, but it seems much to unreliable to be trusted.


Sign in to add a comment
Powered by Google Project Hosting