Page 1 of 1

onsubmit and action

Posted: Tue Aug 17, 2010 4:46 am
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.

Re: onsubmit and action

Posted: Tue Aug 17, 2010 4:52 am
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.

Re: onsubmit and action

Posted: Tue Aug 17, 2010 5:02 am
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. (

Re: onsubmit and action

Posted: Tue Aug 17, 2010 5:14 am
by amargharat
Any error javascript error it is giving ?

or

Just paste your javascript code here so that i can review it

Re: onsubmit and action

Posted: Tue Aug 17, 2010 9:13 am
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