Jump to content

form submition


rhock_95

Recommended Posts

Is there a simple way to prevent an html form from being submitted (without javascript) if no text is entered?

 

<form action="peop_search.php" method="post">
<input type="text" name="query" />
<input type="submit">
</form>

 

If an invalid query is entered it prints the message below but if nothing is enterd it prints all the records

 

if ($numrows == 0){
echo("No results found matching your query - $query");

 

Is there any way to amend this to echo the above if nothing is entered?

 

 

 

 

Link to comment
Share on other sites

if (isset($_POST)) {

//do any kind of manipulation and output with the posted form data

//like checking for correct/empty form fields

} else {

//if nothing is being posted, the form is then displayed

}

 

PHP is server side, you can only "change" things once a page has been loaded/reloaded, so once the form has been posted you can then decide what to do with the data, Javascript on the other hand can stop the form from being submitted in real time, but i assum ethat is really now what u want, u can still have the form submitted, but just give the impression of it not being submitted if incorrect data has been submitted and u can just simply redisplay the form like it was never submitted

 

perception is the keyword

Link to comment
Share on other sites

It would be helpful to see more code, especially the query you're using.

 

You might try using something like this.

 

if(!isset($_POST['query']) || $_POST['query'] == "")
{
 echo "No results found matching your query - $query";
}
else
{
 // process query using $_POST['query']
}

 

This Almost works... what it does is print the "No results found matching your query" above each record...but it is still printing all the records

Link to comment
Share on other sites

I would like to oblige but the script is so loaded with my own personal comments it would take me half an hour just to strip all the comments...

 

is there a particula part of the script that would help specifically?

 

the script queries a database for a single column but has pagination results...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.