Submit doesn't works if Action present in the form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
saifphp
Forum Newbie
Posts: 6
Joined: Tue Jul 26, 2011 4:55 am

Submit doesn't works if Action present in the form

Post 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.
Last edited by Benjamin on Tue Jul 17, 2012 11:52 pm, edited 1 time in total.
Reason: Added [syntax=php||htm||css||javascript||sql||etc] - Please use [syntax] tags when posting code in the forums! Thanks.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

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

Post 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"?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
saifphp
Forum Newbie
Posts: 6
Joined: Tue Jul 26, 2011 4:55 am

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

Post 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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

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

Post 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
saifphp
Forum Newbie
Posts: 6
Joined: Tue Jul 26, 2011 4:55 am

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

Post 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
Post Reply