PDA

View Full Version : PHP form to open colorbox


cocoonfx
02-18-2013, 05:53 PM
Hi I am a little stuck with a PHP form and a lightbox. I can get the light box to work if I have a second link to fire the lightbox. My aim is to use just the submit button. Has anyone got any ideas on how to do this?


<script type="text/javascript" src="<?php echo get_template_directory_uri();?>/js/jquery.colorbox-min.js"></script>
<script type="text/javascript">

$(document).ready(function(){

$(".inline").colorbox({inline:true, width:"50%"});

});

</script>



<?php
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$a = $num1*$num2;


;?>
<form name="form1" method="post" action="">

<label for="textinput">Your Hourly Rate</label>
<br />
<input type="text" id="textinput" name="num1" class="textinput" maxlength="25" />
<br />
<label for="textinput2">Hours a day spent on admin</label>
<br />
<input type="text" id="textinput2" name="num2" class="textinput" maxlength="25" />
<br />

<input type="submit" id="submit" name="submit" value="Submit" />

<p><a class='inline' href="#inline_content">ttt</a></p>

</form>

<!-- This contains the hidden content for inline calls -->
<div style='display:none'>

<div id='inline_content' style='padding:10px; background:#fff;'>

<?php echo $a; ?>

</div>

</div>

gentleone
02-21-2013, 06:31 PM
You can use the .submit() event in jQuery. Here's a thread on Stackoverflow with an answer that should get you there:
http://stackoverflow.com/questions/7737166/submit-form-jquery-and-show-results-in-colorbox#answer-7737235

jmichae3
03-11-2013, 05:08 AM
are you sure would would not rather use input type="button" onclick="somefunc()" and then simply not use something that's going to submit the whole form contents over the web? if this is the intended purpose, then go for it. otherwise, simpler less internet-based DHTML might be faster and better, not going over the internet (processing locally in the browser only).
also understand that stackoverflow content is licensed.

jmichae3
04-05-2013, 07:51 AM
that first block of code should be a .php file, but you probably already knew this, I wondered about the first box of code since it's an HTML box and not PHP.
view the source code via the browser of your existing page and see if that PHP chunk is being executed properly.

also, do you want .inline (the entire class of CSS, every instance that uses this) or #inline (for a specific id)?

please explain the documentation for .colorbox(), I don't see it in jquery. it is not in danny goodman's javascript bible 7th ed, index.
http://api.jquery.com/?s=.colorbox