Form action to self and other page

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
Elasek
Forum Newbie
Posts: 4
Joined: Fri Sep 05, 2014 3:56 am

Form action to self and other page

Post by Elasek »

hi,

How can i make a <form> have 2 submit buttons, and make 1 to go to the same page (like action="", or phpself, whatever works.)
and the other submit button to an other page (like action="otherpage.php").

They both have to take the data from the input field ofcourse.

I found on the internet to try use functions like this:

<form action='default.php'>
<button onclick='updateform()' value='edit'/>
<button onclick='submitform()' value='delete'/>
</form>

function updateform() {
$('form').action = 'editaction.php';
$('form').submit();
}

function submitform) {
$('form').action = 'deleteaction.php';
$('form').submit();
}

but when i run it, i just get a blank page.

Hope someone can help me.

Thanks in advance.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Form action to self and other page

Post by Celauran »

Which blank page are you getting? Also, as buttons submit the form by default, you'll want to preventDefault on click.
Elasek
Forum Newbie
Posts: 4
Joined: Fri Sep 05, 2014 3:56 am

Re: Form action to self and other page

Post by Elasek »

Just a whole blank page, nothing on it. that happens here in i guess when the code is not working, had it before.

maybe it helps if i show some more.

This is what i have made so far: http://prntscr.com/4ku356
when i click on one of the buttons it refreshes this same page so it updates the title or whatever is edited.

Now i want that when i click the button on the right side i go to an other page(savereport.php) with the same data as when i click on the left one.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Form action to self and other page

Post by Celauran »

I'd start by turning on error reporting so you get something more meaningful than a blank page. In your initial example, you specified three form actions; default, editaction, and deleteaction. This means there are three different scripts that could be failing, and the JS functions may or may not be failing as well.
Elasek
Forum Newbie
Posts: 4
Joined: Fri Sep 05, 2014 3:56 am

Re: Form action to self and other page

Post by Elasek »

I just found out i can simply use: onclick="form.action='savereport.php'" to get somewhere else than the form action.

Thanks for the help tho, im certainly going to add some error pages so i can see whats going on next time.
Post Reply