i have a form with a textarea and a button. if the button is clicked while the textarea is empty, the form will reload and generate an error message. otherwise, the form will redirect to another page. now, i integrated a jquery dialog box. when the button is clicked the dialog box should appear and ask a yes or no question. the problem is when i click the button the dialog box appears but disappears after a few seconds. how can i fix this? i'm using php for the form and jquery for the dialog box.
ps. in php, when you click a button in a form the page will reload right? i think this has something to do with the disappearing of the box because it disappears right before it reloads.
here's my code
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>" enctype="multipart/form-data" onsubmit="myRedirect();">
<p class="style16">
<div align="left">
<p><span class="style5">Rules:</span>
<?
if($_POST['continue']) {
if($_POST['rules']==null) {
echo $_SESSION['nature']."<font color='red' size='3'><b>Please enter the rules.</b></font><br>";
}
}
?>
<input type="hidden" name="other_id" value="<? echo $_SESSION['other_id']; ?>">
<input type="hidden" name="hidden1" value="<? echo $_SESSION['hidden1']; ?>">
</p>
<p>
<textarea name="rules" rows="7" cols="49"></textarea>
<br />
</p>
<div id="dialog" title="Empty the recycle bin?">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Is the judge/speaker/facilitator from UST?</p>
</div>
<p><input type="submit" name="continue" id="continue" value="Continue"/>
<input type="reset" name="clear" value="Clear"></p>
<center>
<!--<input type="submit" name="clear2" id="clear2" value="Clear" onClick="textfield.value="" textfield2.value="" textarea.value="" textarea2.value=""
textarea3.value="" textarea4.value="" textarea5.value="" textarea6.value="" file.value="" "/>-->
</center>
</p>
</div>
</form>
To keep the form from submitting, you need a "return false" in its onsubmit event.
Related
I am new to PHP and I am trying to get information from a form to another page, but the data won't transfer over when I hit submit. What am I doing wrong? Should I be trying to use GET instead of POST? What is the best way to debug something like this?
The path to information.php is definitely correct.
<form action="information.php" method="post" type="post">
<div class="row" style="padding-bottom: 20px;">
<label name="tempID"><?php echo $number; ?></label>
<button class="btn" name="submit" type="submit">More Details</button>
</div>
</form>
This file is in a different page (information.php)
if (isset($_POST["tempID"]))
{
$infoID = $_POST['tempID'];
}
echo $infoID;
<input type="hidden" name="tempID" value="<?php echo $number; ?>" />
Add this next to your original echo, post variables can't be stored in a label. Also remove the name value from the label
You need a submit input instead of a button with the name submit. Change the button's html to:
<input type='submit' value='More Details'>
Change Label in input
<form action="information.php" method="post">
<div class="row" style="padding-bottom: 20px;">
<input name="tempID" value="<?php echo htmlentities($number); ?>"/>
<button class="btn" name="submit" type="submit">More Details</button>
</div>
</form>
labels are only to display information. they are not submitted during form submission.
<form action="information.php" method="post" type="post">
<div class="row" style="padding-bottom: 20px;">
<label>Number:</label>
<input name="tempID" value="<?php echo $number; ?>"/>
<input class="btn" id="submit" name="submit" type="submit" value="More Detail" />
</div>
</form>
i have a simple website which is written by php code. i have a detect button on my page and given below code is writen for this function but my problem is i need a popup window when the detect link is clicked. i have tired to set a code in my created code but i am not able .kindly please help me solve this problem.
<?php
/*echo "permessi".$permessi;
echo "<br>id".$id_nome;*/
if($action=='canc'){?>
<h1>are you sure want to delect the course?</h1>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="canc1" style="float: left; margin-left:25px;">
<input type="hidden" name="idcorsocanc" value="<?=$canc_id?>">
<input type="hidden" name="action" value="">
<input type="submit" name="ok" value="Si,cancella" class="puls_invia">
</form>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="canc2" style="float: left; margin-left:25px;">
<input type="hidden" name="action" value="">
<input type="submit" name="ok" value="NO" class="puls_invia">
</form>
<?php
}
Try this
<script>
function open_win()
{
window.open("URL HERE")
}
</script>
<input type="button" value="Open Window" onclick="open_win()">
I have a form with two "a" links. Both should submit form, but in two different ways.
This is html I currently have.
HTML:
<form method="post" id="doc_form" target="somwhere">
<textarea name="doc_text"><?php echo $file; ?></textarea>
<input type="hidden" name="submitted" value="1" />
</form>
<a id="doc_send_email" class="btn">SEND</a>
<a id="pritn_pdf_btn" onclick="document.getElementById('doc_form').submit();" class="btn">Print <span class="span_pdf">PDF </span></a>
When user clicks on #pritn_pdf_btn, then the form is submitted to index.php with target="somwhere". On server side I am generating pdf with value from textarea and this PDF is opened in new tab (target="somwhere" is some trick that opens pdf in new tab).
However, now I also need submit form on #doc_send_email click. In this case I also need to generate PDF, but it should be sent to provided email and then it should show confirmation message on the same page. So:
In index.php I need somehow distinguish what caused form submission (pritn_pdf_btn) or (doc_send_email). If I would be able to set some variable on #pritn_pdf_btn.click and on #doc_send_email.click and then sent it via POST, it would help. But I could not find sollution.
I need some way to submit form with target="somwhere" and without target="somwhere". Probably, there is someway on the #pritn_pdf_btn.click and on #doc_send_email.click to submit form with and without target?
It's easier to do it with multiples submit buttons like this:
<form method="post" id="doc_form" target="somwhere">
<textarea name="doc_text"><?php echo $file; ?></textarea>
<input type="hidden" name="submitted" value="1" />
<input type="submit" name="email" value="1" id="doc_send_email" class="btn" value="SEND"/>
<input type="submit" name="pdf" value="1" id="pritn_pdf_btn" class="btn" value="Print PDF"/>
</form>
Then at backend (asuming it is PHP)
if($_POST['email'])
sendEmail();
else
generatePDF();
Or by using JS:
<form method="post" id="doc_form" target="_self">
<textarea name="doc_text"><?php echo $file; ?></textarea>
<input type="hidden" name="submitted" value="1" />
<input type="hidden" name="action" id="action" value="generate" />
</form>
<a id="doc_send_email" onclick="document.getElementById('action').value='email';document.getElementById('doc_form').submit();" class="btn">SEND</a>
<a id="pritn_pdf_btn" onclick="document.getElementById('action').value='generatePdf';document.getElementById('doc_form').target='somwhere';document.getElementById('doc_form').submit();" class="btn">Print <span class="span_pdf">PDF </span></a>
Then at backend (asuming it is PHP)
if($_POST['action']=='email')
sendEmail();
else
generatePDF();
Hi having a problem with this code even if i clicked on cancel it will still proceed to use the action of my form even though the CANCEL button is not part of the form, Would appreciate any help.
Here is the code.
<form method="post" action="input_enroll.php" >
<div id="overlay1">
<div>
<h1> Enter Educational Level Entry</h1>
<input type="text" name="level" >
<input type="submit" value="Proceed To Enroll" '>
</form>
<input type="submit" value="Cancel" onclick='overlay()'>
</div>
</div>
EDIT: Any suggestions what would be a better idea? I'm thinking putting the cancel outside the div.
You are having form started, then divs started, then form closed..start form after divs..
as your markup is not correct, browsers will change it as thier parser suggest,
In chrome </form> tag is postponed after </div>s..
<div id="overlay1">
<div>
<form method="post" action="input_enroll.php" >
<h1> Enter Educational Level Entry</h1>
<input type="text" name="level" />
<input type="submit" value="Proceed To Enroll" />
</form>
<input type="submit" value="Cancel" onclick='overlay()' />
</div>
</div>
I have a 3 page registration page. After the user selects an option on the first page and clicks submit, the form transforms into the next form using jquery's animate method, meaning it stays on the same page. The question I have is how to get the data from the first form because the content of the 2nd forms is dependent on that information. Here's my html:
<div id="Registration" style="display:none;">
<div class="box">
<form id="frmtype1" action="#" name="frmtype1" method="post">
<header>Registration Options</header><br/>
<label for="Reg_type1"><input type="radio" name="Reg_type" id="Reg_type1" value="1"/> Option 1</label> <br/><br/>
<label for="Reg_type2"><input type="radio" name="Reg_type" id="Reg_type2" value="2"/> Option 2</label><br/><br/>
<label for="Reg_type3"><input type="radio" name="Reg_type" id="Reg_type3" value="3"/> Option 3</label><br/><br/>
<p id="error_message" style="display:none">Please choose an option</p><input type="submit" class="button" name="Submit" value="Submit"/>
</form>
<form name="everything" id="everything" action="#" method="post">
<header>Registration Information</header><br/>
<label>First Name<font color="red">*</font>: <input type="text" name="fname" id="fname" /> </label><br/>
Last Name*: <input type="text" name="lname" id="lname" /> <br/>
Address*: <input type="text" name="address" id="address" /> <br/>
</form>
</div>
</div>
So once an option is selected, the first form disappears and the next one appears. So how do I get the data of which option they selected? Thanks
Since they depend on information on one form, the "pages" should really be the same form. You use the jQuery/JavaScript to show/hide the "current page". This will allow you to submit all the data in one go.
Wrap all the input elements in one html form tag
For each form "segment" you will need to use your js to hide/show the wrapping HTML container. The default being "page 1" of the form and the rest hidden.
Change your submit button to just a button and have a on click event on it. When the user clicks the button the input is validated and then the jQuery unhides "page 2".
On your last "page" have a normal submit button and then all the form data is posted in one.
For example, the html might look like this:
<script type="text/javascript">
$(document).ready(function{
$(".next-page").click(function(){
$(".box-wrapper").hide();
$("#page-" + $(this).data("page")).show();
});
});
</script>
<div class="registration">
<form name="regform" action="" method="post">
<!-- Page 1 -->
<div class="box-wrapper" id="page-1">
<div class="box">
<!-- form inputs go here -->
<input type="button" name="next-page" class="next-page" value="Continue" data-page="2"/>
</div>
</div>
<!-- Page 2 -->
<div class="box-wrapper" id="page-2" style="display: none;">
<div class="box">
<!-- form inputs go here -->
<input type="button" name="next-page" class="next-page" value="Continue" data-page="3"/>
</div>
</div>
<!-- Page 3 -->
<div class="box-wrapper" id="page-3" style="display: none;">
<div class="box">
<!-- form inputs go here -->
<input type="submit" name="submit" class="submit" value="Complete Registration"/>
</div>
</div>
</form>
</div>
Using jquery --- $('input[name=Reg_type]:checked').val() this will give you the selected value.