Jump to content

PHP and Web forms question


turkman

Recommended Posts

Well i actually have two questions.

 

1) Last night i was trying to use a php script to generate a web form. i was using sprintf im sorry i don't have the code but it was late last night and i gave up and now im in work. Basically the web form displayed ok, but when i clicked the submit button, nothing happened even though id asked the form to open blah.php in the action part.

 

I was wondering if this is a problem because i tried to make the form using php ? or if this is a normal problem, i dont have the code but it was basically <form action="blah.php method=GET> then i had two text boxes and a submit button

 

 

2)as opposed to getting a submit button to call a new page, can you get it to call a php function on the same page?

Link to comment
https://forums.phpfreaks.com/topic/112560-php-and-web-forms-question/
Share on other sites

this:

<form action="blah.php method=GET>

 

needs to be this:

<form action="blah.php" method="GET">

 

then on blah.php if you want to call a function you just setup blah.php like this:

<?php
// call whatever functions here
echo "I just called the echo function";
?>

 

Regards ACE

depends what he wants. If he wants the form to go to a new page. Then my way is all he needs, but if he wants to submit the info to the same page the form is on, he can do that with just PHP anyway. But if he wants it dynamic then he will need AJAX.

Hey, thanks for the replies, in regards to the first one when i typed it out i didnt have a ending quote after the blah.php but i dont think i had the GET in quotes which may have caused the error?

 

I assumed it was because i was building it with sprintf and adding the quotes like this \"  Im not sure.

 

Regarding the second question, i don't need ajax, i just need to post whats in the form into the database when they click submit, usually ive added a new file like postdata.php and called that, but its making a huge number of files and im starting to think its unnecessary. is there any reason i can't  just call a function in the same page and get it to submit the data?

 

How would that work <form action="enterdata()" > can someone show me how to make the submit button call a function to enter the data into the database.

 

hope this is clearer

<?php

if(isset($_GET['name']) && strlen(trim(stripslashes($_GET['name']))) > 0) {) { // thanks to ken for the replacement for empty()

mysql_query("") or die("Query could not execute!");

} else {
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<input type="text" name="name">
<input type="submit" value="submit">
</form>

<?php } ?>

 

thats very basic.

 

Regards ACE

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.