Page 1 of 1

Submit doesn't works if Action present in the form

Posted: Tue Jul 17, 2012 11:47 pm
by saifphp
Hi,

I have created an input form in php which will submit data to ms access2010 database and after submitting go to another page which is mentioned in form action. But if I use the url for another page in action, data don't insert into the database. If I remove the action than the data is inserted. I am giving the code bellow-

Code: Select all

<script> 
function inputvalidation()
{
if (document.getElementById('Com_Name').value == '') { 
  alert('Insert Name'); 
  return false; // stop submission until textbox is not ''
  }
  else if (document.getElementById('Email').value == '') { 
  alert('Insert Email'); 
  return false; // stop submission until textbox is not ''
  }
  else if (document.getElementById('Address').value == '') { 
  alert('Insert Address'); 
  return false; // stop submission until textbox is not '' 
  }
  else 
  {
  this.document.form1.mode.value='submit';
  this.document.form1.submit();
   }
} 
</script> 

<html>
<form name="form1" method="post" onSubmit="return inputvalidation()" action="proc_detail.php?id=<?php echo odbc_result($qResult_main,'Proc_ID')?>">
<table align="center" style="font-family:Verdana; font-size:11px; color:#FF0000; font-style:italic;">
<tr>
<td width="20%"></td>
<td width="80%"><input name="Deadline" type="date" id="Deadline" size="20" value="<?php echo odbc_result($qResult_main,'Proc_Deadline')?>" style="visibility:hidden"></td>
</tr>
<tr style="background-color:#D2D2F9;"><td width="20%"><b>Company Name<font style="color:#FF0000">*</font>:</b></td>
<td width="80%"><input name="Com_Name" type="text" id="Com_Name" size="70" style="font-size:12px;"></td>
</tr>
<tr style="background-color:#D2D2F9;">
<td width="20%"><b>Email<font style="color:#FF0000">*</font>:</b></td>
<td width="80%"><input name="Email" type="text" id="Email" size="70" style="font-size:12px;"></td>
</tr>
<tr style="background-color:#D2D2F9;">
<td width="20%"><b>Address<font style="color:#FF0000">*</font>:</b></td>
<td width="80%"><input name="Address" type="text" id="Address" size="120" style="font-size:12px;"></td>
</tr>
<td>
<input type="submit" name="Submit" value="Submit" class="hilite">
<input type="hidden" name="mode" value="submit">
</td>
</tr>
<td></td><td></td></tr>
</table>
</form>
</html>
please guide me.

Re: Submit doesn't works if Action present in the form

Posted: Wed Jul 18, 2012 5:44 am
by social_experiment
saifphp wrote:I have created an input form in php which will submit data to ms access2010 database and after submitting go to another page which is mentioned in form action. But if I use the url for another page in action, data don't insert into the database. If I remove the action than the data is inserted. I am giving the code bellow-
Could you clarify what you mean by "another page"?

Re: Submit doesn't works if Action present in the form

Posted: Thu Jul 19, 2012 3:38 am
by saifphp
Hi,

Thanks for your replay.

Another page means the target page which I want to show after submitting data. By clicking on the submit button, two things will be happened- 1. data will go to the database, 2. another page will be displayed which I mentioned in the form action.

Thanks again.

Re: Submit doesn't works if Action present in the form

Posted: Thu Jul 19, 2012 4:38 am
by social_experiment
saifphp wrote:If I remove the action than the data is inserted
This means that the code that inserts the data into the database is on the same page as the form. It's refered to as 'calling the form on itself'. Is there any other code on the form page?
saifphp wrote:By clicking on the submit button, two things will be happened- 1. data will go to the database, 2. another page will be displayed which I mentioned in the form action.
If you want something to display on the target page it has to be placed on the target page and (usually) be dependent on the results of something, in your instance submitting data to the database. A simple example

Code: Select all

 if (insertedIntoDatabase)
    'Data successfully added'
 else 
    'Data wasnt added.'
If you have the message on a totally different page than the value in the target attribute you would redirect depending on the result of something. You could use header() or perhaps a javascript alternative to achieve this.

Re: Submit doesn't works if Action present in the form

Posted: Thu Jul 19, 2012 6:26 am
by saifphp
Thanks a lot for your support

Your suggestion was very very much helpful and my problem is solved. I have used a separate page for inserting data and than redirected to the target page.

Thanks again