Closed Thread Icon

Topic awaiting preservation: Form functions in PHP (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=12154" title="Pages that link to Topic awaiting preservation: Form functions in PHP (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Form functions in PHP <span class="small">(Page 1 of 1)</span>\

 
Dark
Neurotic (0) Inmate
Newly admitted
posted posted 04-01-2002 06:14

I'm trying to write in some javascript function for a form button in PHP.

This is button I got so far

<INPUT TYPE=\"submit\" VALUE=\"Popup\">

But how do I write this as a button in PHP?

code:
<input type="button" value="History" onClick="window.open('http://jonkriek.com/shoutbox-v3/','Shout History','width=160,height=300,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no')" />






[This message has been edited by Dark (edited 04-01-2002).]

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 04-01-2002 12:16

This is one way to do it...

<?php

// PHP code goes here...

function blah() {

if (something) {

?>
<input type="button" value="History" onClick="window.open('http://jonkriek.com/shoutbox-v3/','Shout History','width=160,height=300,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no')" />
<?php

// PHP code goes here...

} // close if

} // close function

?>


bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 04-01-2002 16:39

yeah Max has my favorite trick for PHP right there, you can always drop out of PHP mode to make writing HTML easier. This includes inside loops.




.:[ The Tao of Steve ]:.
Be Desireless
Be Excellent
Be Gone
...................................

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 04-01-2002 16:59

Yes, that one is very handy, not just to avoid having to escape double quotes, but also for syntax coloring benefits in your handy HTML/PHP editor.

Just last Friday I made a multi-page variable form using that trick extensively, but the page was still very long and somewhat difficult to read, so I took it to the next level.

I pulled out the individual forms and stuck them in .html files to be included in the overall script. Very clean.

-jiblet

Dark
Neurotic (0) Inmate
Newly admitted
posted posted 04-01-2002 18:47

I thought this would work great, but it keeps giving me errors

quote:
Parse error: parse error, expecting `','' or `';'' in /home/kriek/public_html/shoutbox-v3/class/shoutbox.php on line 43

Fatal error: Cannot instantiate non-existent class: shoutbox in /home/kriek/public_html/shoutbox-v3/index.php on line 18



Would it help if posted the whole file here? It's not that big.

Sash
Paranoid (IV) Inmate

From: Canada, Toronto
Insane since: May 2000

posted posted 04-01-2002 19:22

Just a question regarding this.

Does it have any performance issues in PHP?

In ASP for example, escaping from one mode to another is generally considered to be a bad practice.
But that is ASP :-)


Sasha.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 04-01-2002 19:36

Um yeah gonna have to see the code if you want help debugging that.

Sash I can't give you a definate answer to that but my instinct would be no, or at least not significant The php parser parses the whole page regardless of tags for PHP code (which is why it's not good to name files .php if there is no php code in them).

I can't speak for how asp works in this regard.



.:[ The Tao of Steve ]:.
Be Desireless
Be Excellent
Be Gone
...................................

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 04-01-2002 19:51

Dark, it would help if you could show us that PHP file (but don't post it here, upload it in txt format somewhere instead)...

Sash, PHP's parser isn't stupid. PHP3's parser was stupid since it parsed whole file (line by line), but on the other hand PHP4's parser is much better. Anyway, everything that's not inside <?php ?> tags is converted internally to series of echo() calls...


Dark
Neurotic (0) Inmate
Newly admitted
posted posted 04-01-2002 20:27

Ok the php code is here

I'm trying to add in the form button directly above the <BR><BR> and inside the <TD> where the other two form buttons are. I really appreciate this.

Sash
Paranoid (IV) Inmate

From: Canada, Toronto
Insane since: May 2000

posted posted 04-01-2002 21:27

Try this:

<input type=\"button\" value=\"History\" onClick=\"window.open('http://jonkriek.com/shoutbox-v3/','History','width=160,height=300,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no')\" >

Sasha.



[This message has been edited by Sash (edited 04-01-2002).]

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 04-01-2002 21:48

That right there is the classic example of where dropping out of PHP mode is easier. The whole function can be written like so:

function displayform() {
?>
<TABLE WIDTH="150" BORDER="0" CELLPADDING="4" CELLSPACING="0">
<FORM NAME="shout" ACTION="post-shout.php" METHOD="post">
<TBODY>
<TR>
<TD ALIGN="center">
<INPUT TYPE="text" VALUE="nick" NAME="shoutnick" SIZE="20"><BR>
<INPUT TYPE="text" VALUE="shout" NAME="shout" SIZE="20"><BR>
<INPUT TYPE="text" VALUE="website" NAME="shoutwebsite" SIZE="20"><BR>
<INPUT TYPE="submit" VALUE="Shout!"> <INPUT TYPE="reset" VALUE="Reset">
<input type="button" value="History" onClick="window.open('http://jonkriek.com/shoutbox-v3/','Shout History','width=160,height=300,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no')" />


<BR><BR>
</TD>
</TR>
</TBODY>
</FORM>
</TABLE>
<?
}

you don't need the echo if you're dropping out of PHP mode like Max said above PHP automatically inserts the "echo" if there is none.

P.S. this is also a gret time to use jiblet's suggestion and put the HTML in an included file to allow others to modify the form without going into the class. It also keeps the code cleaner.



.:[ The Tao of Steve ]:.
Be Desireless
Be Excellent
Be Gone
...................................

[This message has been edited by bitdamaged (edited 04-01-2002).]

Dark
Neurotic (0) Inmate
Newly admitted
posted posted 04-01-2002 23:40

Thanks so much guys. Both ways seem to work well, but for right now I'm going to just have it like sash wrote it. later I think that I will clean the code up a little bit and write it in the other way. Again thanks guys

« BackwardsOnwards »

Show Forum Drop Down Menu