Jump to content


Photo

*SOLVED* PHP Forms Without Submit


  • Please log in to reply
6 replies to this topic

#1 psi-phy

psi-phy
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 30 March 2006 - 04:14 PM

OK I have a wackey question. Is it possible to submit form data WITHOUT using Javascript or a Submit Button? I have a page with a text box. To the right of it are links to "Edit" or "Delete" the data in the text box. How can I make those links submit the form with the data in the textbox?

To give a rough examplt, I pull a value from the database and it goes into a textbox.

<form method="POST" action="index.php?op=groupsmaint">
<input type="text" name="dbdata" value="$data_from_db">
<a href=' ??? '>Edit</a><a href=' ??? '>Delete</a>
</form>

So the form action takes me to my page with the given "op" (Which is just a switch() function call). The problem is that I don't get my "dbdata" from the textbox. So I didn't know if there was a way to "submit" without a "Submit" button. :)

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 30 March 2006 - 04:27 PM

No, you either need a submit button or you have to use Javascript.

Why don't you want to use a submit button?

Ken

#3 psi-phy

psi-phy
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 30 March 2006 - 04:36 PM

Design wise, a submit button would make it look ugly. :)

I was hypothesissing this one.. If there is a javascript form submit function, could I just go like this:

<a href="index.php?op=whatever&var1=value&var2=value" onclick="javascript:formsubmit()">Edit</a>

See I wanted to pass data with the link as well, so I pass data in the link and I also need to submit the textbox as well... I know it's an odd request, but my big complaint is that the submit button is freakig ugly. :)

#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 30 March 2006 - 04:53 PM

Put your other variables into hidden inputs. As far as the javascript call:

<a href="index.php" onclick="document.name_of_form.submit()">Edit</a>

Info: PHP Manual


#5 psi-phy

psi-phy
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 30 March 2006 - 05:19 PM

Yeah I just tried that, and it works, however i realized that I was using ONE form to try to do TWO different things. The hidden fields I made contain commands for which function to load when the page is submitted depending on which link is clicked. The problem is that when it submits, I get BOTH function commands as all the data is in one form. :\ I have a hidden="edit" and a hidden="delete" but they are "in the same form" so both values are submitted and it doesn't work properly. :(

God this sucks :P
hehe

#6 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 30 March 2006 - 05:55 PM

[!--quoteo(post=360070:date=Mar 30 2006, 12:19 PM:name=psi-phy)--][div class=\'quotetop\']QUOTE(psi-phy @ Mar 30 2006, 12:19 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Yeah I just tried that, and it works, however i realized that I was using ONE form to try to do TWO different things. The hidden fields I made contain commands for which function to load when the page is submitted depending on which link is clicked. The problem is that when it submits, I get BOTH function commands as all the data is in one form. :\ I have a hidden="edit" and a hidden="delete" but they are "in the same form" so both values are submitted and it doesn't work properly. :(

God this sucks :P
hehe
[/quote]

why not just converge both the hidden=edit and hidden=delete into 1

<form>
<input type="hidden" name="action" value="">

<a href="index.php" onclick="document.getElementById('action').value ="edit"; 
document.name_of_form.submit()">Edit</a>

<a href="index.php" onclick="document.getElementById('action').value ="delete"; document.name_of_form.submit()">Delete</a>
</form>

Then you can check the $_POST['action'] on the submit and call the function of choice

#7 psi-phy

psi-phy
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 30 March 2006 - 10:17 PM

THANK YOU! That's excatly what I needed. I can do PHP, but unfortunately Javascript is something that completely confuses me, and I'm not too familiar with it. I appreciate the help from everyone! :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users