onsubmit and action

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
Anant
Forum Commoner
Posts: 66
Joined: Wed Jul 14, 2010 11:46 am

onsubmit and action

Post by Anant »

Hi,

I have got a form within abc.php page with method=post, onsubmit="return validateForm(this)" and action="xyz.php"

once user clicks submit - JavaScript function validateForm validates the form onsubmit and if it's all correct the page goes to xyz.php to run the script thr to send email.

But instead of going to the xyz.php page can i have this implemented in the same page ?

I tried placing the xyz.php script in abc.php but it doesn't seem to like it.
Any ideas

Thank you.
amargharat
Forum Commoner
Posts: 82
Joined: Wed Sep 16, 2009 2:43 am
Location: Mumbai, India
Contact:

Re: onsubmit and action

Post by amargharat »

Sure, You can submit to similar page where you are currently, just you have to check posted values are empty are not and then only allow script to proceed for further execution.
Anant
Forum Commoner
Posts: 66
Joined: Wed Jul 14, 2010 11:46 am

Re: onsubmit and action

Post by Anant »

ok so you mean something like below -

Code: Select all


if(isset($_POST['submitted']))
{
 
// send email code goes here...
 
}

if this is correct then it's not working - onsubmit the form goes to javascript function to validate and if validation passes it looks to action and if i set action to same page then nothing happens. (
amargharat
Forum Commoner
Posts: 82
Joined: Wed Sep 16, 2009 2:43 am
Location: Mumbai, India
Contact:

Re: onsubmit and action

Post by amargharat »

Any error javascript error it is giving ?

or

Just paste your javascript code here so that i can review it
Anant
Forum Commoner
Posts: 66
Joined: Wed Jul 14, 2010 11:46 am

Re: onsubmit and action

Post by Anant »

it seems to be working now - strange

now i have another problem - In form we need to type action="abc.php"
but now i have a situation where i don't know the name of the file because it is set up in ids using short url. So is there any way i can force the action to run in the same page without writing the abc.php bit.

Thanks
Post Reply