PHP表单不提交[关闭]

PHP表单不提交[关闭]

问题描述:

I want to submit the form after an if statement for example:

<?Php
if($something){

?>
<script type="text/javascript">
    document.getElementById('dateForm').submit(); // SUBMIT FORM
</script>
<form  id="dateForm" action="https://www.paypal.com/cgi-bin/webscr" method="POST">

<input type="hidden" name="test" value="test">
<input type="hidden" name"test2" value="Support">



</form>
<?php

}
?>

However, this doesn't work.

Put the script after the form tag. It searches dateForm id and until that no form is in the output so it does nothing. When you place that after it, it'll search the page for that id and it finds that and submits.

<?Php
if($something):?>

<form  id="dateForm" action="https://www.paypal.com/cgi-bin/webscr" method="POST">
<input type="hidden" name="test" value="test">
<input type="hidden" name"test2" value="Support">
</form>

<script type="text/javascript">
    document.getElementById('dateForm').submit(); // SUBMIT FORM
</script>

<?php
endif;?>