Jump to content

problem with nested forms..


php_begins

Recommended Posts

I have a problem with nested forms.. when i click the submit button at the bottom of the page i want it to take to display.php and when i click the upload button on the upload form code i do not want to refresh it.

But right now when i click on upload button it takes me to display.php.

Can someone help me out with the code?

<?
include("db.php");
include("upload.php");
error_reporting(E_ALL ^ E_WARNING);
ini_set("display_errors", 1);

<script type="text/javascript">
function initUpload() {

   /*set the target of the form to the iframe and display the status
      message on form submit.
  */
document.getElementById('uploadform').onsubmit=function() {
document.getElementById('uploadform').target = 'target_iframe';
    document.getElementById('status').style.display="block";

}
}

//This function will be called when the upload completes.
function uploadComplete(status){
   //set the status message to that returned by the server
   document.getElementById('status').innerHTML=status;
}

window.onload=initUpload;
</script>

<style type="text/css">
.color
{
   font-weight:bold;
   color:black;
}
</style>


<div class="color">

<body bgcolor="white">
<center><h4><font color="blue">CREATE NEWSLETTER</font></h4></center>
<table align="center" bgcolor="silver">
<form action="display.php" method ="post">

<tr>
   <td>Site: </td>
   <td>
   <select name="new_id">
   <option value="">=============</option>
   <?php foreach($acronym as $key=>$value){ ?>
   <option value="<?php echo $value['site_id']; ?>"><?php echo $value['acronym']; ?></option>

   <?php }?>
   </select>
   </td>
</tr>

<tr>
   <td> Title: </td>
   <td><input type="text" size ="40" name="newsletter_title" /></td>
</tr><tr>
<td>Greeting:</td>




<td><textarea rows="10" cols="80" name="greeting" ></textarea></td>
</tr>

   <td> URL Title: </td>
   <td><input type="text" size ="40" name="url_title" /></td>
</tr>

<tr>
   <td> URL: </td>
   <td><input type="text" size ="40" name="newsletter_url" />Begin url with http://</td>
</tr>

<tr>
  <td  align="center">
  <b><font color="#214754" size="3">Banners</b></font>
  </td>
</tr>
<tr>
   <td>Banner Image URL: </td>
   <td><input type="text" size ="40" name="banner_url1" />
   Banner Link:
   <input type="text" size ="40" name="banner_link_url1" />
   </td>
</tr>
<tr>
   <td>Banner Image URL: </td>
   <td><input type="text" size ="40" name="banner_url2" />
   Banner Link:
   <input type="text" size ="40" name="banner_link_url2" />
   </td>
</tr>
<tr>
   <td>Banner URL: </td>
   <td><input type="text" size ="40" name="banner_url3" />
    Banner Link:
   <input type="text" size ="40" name="banner_link_url3" />
   </td>
</tr>
<tr>
   <td>Banner URL: </td>
   <td><input type="text" size ="40" name="banner_url4" />
   Banner Link:
   <input type="text" size ="40" name="banner_link_url4" />
   </td>
</tr>
<tr>
  <td  align="center">
  <b><font color="#214754" size="3">Threads</b></font>
  </td>
</tr>

   <select name="category1">
   <option value="">==========</option>
   <option value="registry">Registry</option>
   <option value="reviews">Reviews</option>
   <option value="classifieds">Classifieds</option>
   </select>
   </td>
</tr>

<tr>
   <td> Title: </td>
   <td><input type="text" size ="40" name="registry_title1" /></td>
</tr>
<tr>
   <td> Image: </td>
   <td><input type="text" size ="40" name="registry_img1" /></td>
</tr>

<tr>
   <td> URL: </td>
   <td><input type="text" size ="40" name="registry_url1" />Begin url with http://</td>
</tr>
<tr>
   <td height='12'></td>
</tr>
<tr>
   <td> Title: </td>
   <td><input type="text" size ="40" name="registry_title2" /></td>
</tr>
<tr>
   <td> Image: </td>
   <td><input type="text" size ="40" name="registry_img2" /></td>
</tr>
<td>
<form id="uploadform" method="post"
enctype="multipart/form-data"
action="upload.php">

<input name="file" id="file" size="27" type="file" /><br />
<input type="submit" name="action" value="Upload" />
<span id="status" style="display:none">uploading...</span>
<iframe id="target_iframe" name="target_iframe" src="" style="width:0;height:0;border:0px"></iframe>

</form>

</td>


<tr>
   <td> URL: </td>
   <td><input type="text" size ="40" name="registry_url2" /></td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="submit" />
</td>
</tr>
</form>
</table>
</div>

Link to comment
https://forums.phpfreaks.com/topic/249792-problem-with-nested-forms/
Share on other sites

In researching this, here are three suggestions I found -

 

1) Place the two forms side by side and use css to position the ajax upload form where you want it over the main form.

 

2) Popup the ajax upload form by clicking a link in the main form.

 

3) Make 3 forms. The 1st form does not have a submit button and includes everything before the ajax upload form, then the upload form, then the remainder of the main form. The 3rd from's submit button will cause javascript code to read the 1st form's values into hidden fields in the 3rd form and submit the 3rd form.

 

Edit: or an alternative to method #3 would be to add an onchange event to each field in the 1st form that automatically copies the value to the corresponding hidden field in the 3rd form.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.