PHP Form not submitting on specific pages, same code - php

I have the following Form code:
<form method=post action='/zoeken.php'>
<div style='position: relative;'>
<input type=search name=zoeken_opdracht placeholder='Zoeken...' value="<?php echo $_POST['zoeken_opdracht']; ?>">
<button name=zoeken><i class='fa fa-search'></i></button>
</div>
</form>
However, when I am submitting in on specific pages, it isn't submitting. The same code however works fine on all other pages (No product pages).
See examples of productpage here:
Productpage (Form not working)
You can find the other forms on any other page but the productpages. For instance the homepage.

Change button with submit
Careful that there are errors in the type search, in the form method, in some name and style
<form method="post" action="/zoeken.php">
<div style="position:relative;">
<input type="search" name="zoeken_opdracht" placeholder="Zoeken..." value="<?php echo $_POST['zoeken_opdracht']; ?>">
<input type="submit" name="zoeken"><i class="fa fa-search"></i>
</div>
</form>

<form method=post action='/zoeken.php'>
<div style='position: relative;'>
<input type="search" name="zoeken_opdracht" placeholder='Zoeken...' value="<?= $_POST['zoeken_opdracht']; ?>">
<button type="submit" name=zoeken><i class='fa fa-search'></i></button>
</div>
</form>

The problem is solved. I figured out that there was a preventDefault in my javascript code that was also triggered on the search form submission. I fixed this and now it works like a charm.
Thanks for the

Related

PHP get request with multiple parameters from different forms

I'm new to PHP and have a little problem. I'm trying to set up a get Request with two parameters. The URL should for example look like this:
search.php?query=Harry+Potter&page=movies
The problem is, that i get the two parameters 'query' and 'page' from two different forms.
My Code is the following:
Form 1:
<form action="search.php" method="get" class="navbar-form" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="query">
<div class="input-group-btn">
<button class="btn btn-default c-nav-btn-height" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
Form 2:
<form class="btn-group-vertical" action="search.php" method="get">
<button id="bMovies" class="btn active-menu" type="submit" name="page" value="movies">Filme</button>
<button id="bSeries" class="btn" type="submit" name="page" value="series">Serien</button>
</form>
Are there any possibilities to combine two forms in one get Request?
I as able to fix the problem with some help from the comment section - thanks to #Magnus Eriksson. Unfortunately he deleted some of his comments, so I will answer this questions by myself.
To clarify, I know this is for sure not the best way to do it, but Hell Yeah, it works!
Solution:
Hidden input fields did it for me. I added one hidden input field in each form:
Form 1:
<form action="search.php" method="get" class="navbar-form" role="search">
<div class="input-group">
<input type="hidden" name="page" value="movies">
<input type="text" class="form-control" placeholder="Search" name="query">
<div class="input-group-btn">
<button class="btn btn-default c-nav-btn-height" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
Form 2:
<form class="btn-group-vertical" action="search.php" method="get">
<button id="bMovies" class="btn active-menu" type="submit" name="page" value="movies">Filme</button>
<button id="bSeries" class="btn" type="submit" name="page" value="series">Serien</button>
<input id="hiddenField" type="hidden" name="query" value="">
</form>
So I added a hidden input field named "page" in the first form and a hidden input field named "query" in the second form. With this little trick im able to get the same information in both forms, but only the fields I want to show are shown.
Since the Form 1 is submitted first, it is possible to copy the value of the visible input field into the invisible input field in Form 2. All i need is some extra PHP and JavaScript.
$query = $_GET["query"];
$page = $_GET["page"];
if ($page == "movies" || $page == "series") {
echo "<script>";
echo 'document.getElementById("hiddenField").value = "'. $query .'" ;';
echo "</script>";
}
else {
}
I store the two parameters from the first Form into variables and check if $page is 'movies' or 'series', because only these two options are allowed on this site. If it is true, it echos some JavaScript, which is adding the $query variable as the value of the hidden input field in the second form.
And again, i know there will be better ways to do it, but it worked for me and i wanted to share it with you.
well, not natively, and if you can avoid it, you should. if you can combine both forms on your page, do that. if.. for some reason you really can't, i suggest you have a look at this thread.. it has a javascript function to do what you are looking to accomplish
jQuery - submit multiple forms through single reqest, without Ajax

Wordpress Search Submit Not Working

My search was working great before I changed the style of the form.
Now the search will not submit.
Here is my searchform.php:
<button type="button" class="close">×</button>
<form role="search" method="get" action="<?php echo home_url( '/' ); ?>">
<input type="search" value="<?php get_search_query(); ?>" name="s" placeholder="search..." title="Search" />
<button type="submit" id="searchsubmit" class="btn btn-default btn-search" value="Search"><i class="fa fa-search fa-4x"></i></button>
</form>
I am developing on site http://www.2knowmusic.net. Search is on the top right.
Check out your footer or where the following is located. In the source code, you have:
//Do not include! This prevents the form from submitting for DEMO purposes only!
$('form').submit(function(event) {
event.preventDefault();
return false;
})
This is preventing your form from being submitted which is why it's not doing anything.

Can't retrieve values from other page (Stored As Label)

I am new to PHP and I am trying to get information from a form to another page, but the data won't transfer over when I hit submit. What am I doing wrong? Should I be trying to use GET instead of POST? What is the best way to debug something like this?
The path to information.php is definitely correct.
<form action="information.php" method="post" type="post">
<div class="row" style="padding-bottom: 20px;">
<label name="tempID"><?php echo $number; ?></label>
<button class="btn" name="submit" type="submit">More Details</button>
</div>
</form>
This file is in a different page (information.php)
if (isset($_POST["tempID"]))
{
$infoID = $_POST['tempID'];
}
echo $infoID;
<input type="hidden" name="tempID" value="<?php echo $number; ?>" />
Add this next to your original echo, post variables can't be stored in a label. Also remove the name value from the label
You need a submit input instead of a button with the name submit. Change the button's html to:
<input type='submit' value='More Details'>
Change Label in input
<form action="information.php" method="post">
<div class="row" style="padding-bottom: 20px;">
<input name="tempID" value="<?php echo htmlentities($number); ?>"/>
<button class="btn" name="submit" type="submit">More Details</button>
</div>
</form>
labels are only to display information. they are not submitted during form submission.
<form action="information.php" method="post" type="post">
<div class="row" style="padding-bottom: 20px;">
<label>Number:</label>
<input name="tempID" value="<?php echo $number; ?>"/>
<input class="btn" id="submit" name="submit" type="submit" value="More Detail" />
</div>
</form>

editing HTML in Joomla pages

I'm no too used to or familiar with the Joomla system. SO I kind of need your help here. Here's my problem.
I'm building a site, but the template came with problems and the template makers refuse to accept they made a mistake. AS Templates Don't buy from these guys unless you don't care about being on your own if something happens.
Anyway, basically, the site's buttons are all out of alignment. I tried fixing them through CSS but no luck. Some things can't be fixed in the CSS files because they belong to the HTML part of it. But as some of you may know, Joomla is PHP not HTML. So my question is how do I fix an HTML line of code in Joomla?
To be specific:
I have this code in my site
<form name="logoutForm" method="post" action="/">
<button class="btl-buttonsubmit"onclick="document.logoutForm.submit();" name="Submit" style="">Log out</button>
<input type="hidden" value="com_users" name="option">
<input type="hidden" value="user.logout" name="task">
<input type="hidden" value="aW5kZXgucGhwP0l0ZW1pZD0xMDE=" name="return">
<input type="hidden" value="1" name="7b6cc3e246acff3e3943410a6f4919cf">
</form>
Since this is not PHP code or CSS I cant find it anywhere
Here are the screenshots of my two trouble areas
and
Thanks again
I'm re-editing this to add the code for the search results. Please review for me, refer to the screenshot as well to see what I see or go to my site and search for anything
<?php
defined('_JEXEC') or die;
$lang = JFactory::getLanguage();
$upper_limit = $lang->getUpperLimitSearchWord();
JHtml::_('bootstrap.tooltip');
?>
<form id="searchForm" action="<?php echo JRoute::_('index.php?option=com_search');?>" method="post">
<div class="btn-toolbar">
<div class="btn-group pull-left">
<input type="text" name="searchword" placeholder="<?php echo JText::_('COM_SEARCH_SEARCH_KEYWORD'); ?>" id="search-searchword" size="30" maxlength="<?php echo $upper_limit; ?>" value="<?php echo $this->escape($this->origkeyword); ?>" class="inputbox" />
</div>
<div class="btn group pull-left">
<button name="Search" onclick="this.form.submit()" class="button btn btn hasTooltip" title="<?php echo JText::_('COM_SEARCH_SEARCH');?>"><span class="icon-search"></span></button>
</div>
<input type="hidden" name="task" value="search" />
<div class="clearfix"></div>
</div>
<div class="searchintro<?php echo $this->params->get('pageclass_sfx'); ?>">
<?php if (!empty($this->searchword)):?>
<p><?php echo JText::plural('COM_SEARCH_SEARCH_KEYWORD_N_RESULTS', '<span class="badge badge-info">'. $this->total. '</span>');?></p>
<?php endif;?>
</div>
<fieldset class="phrases">
<legend><?php echo JText::_('COM_SEARCH_FOR');?>
</legend>
<div class="phrases-box">
<?php echo $this->lists['searchphrase']; ?>
</div>
<div class="ordering-box">
<label for="ordering" class="ordering">
<?php echo JText::_('COM_SEARCH_ORDERING');?>
</label>
<?php echo $this->lists['ordering'];?>
</div>
</fieldset>
<?php if ($this->params->get('search_areas', 1)) : ?>
<fieldset class="only">
<legend><?php echo JText::_('COM_SEARCH_SEARCH_ONLY');?></legend>
<?php foreach ($this->searchareas['search'] as $val => $txt) :
$checked = is_array($this->searchareas['active']) && in_array($val, $this->searchareas['active']) ? 'checked="checked"' : '';
?>
<label for="area-<?php echo $val;?>" class="checkbox">
<input type="checkbox" name="areas[]" value="<?php echo $val;?>" id="area-<?php echo $val;?>" <?php echo $checked;?> >
<?php echo JText::_($txt); ?>
</label>
<?php endforeach; ?>
</fieldset>
<?php endif; ?>
<?php if ($this->total > 0) : ?>
<div class="form-limit">
<label for="limit">
<?php echo JText::_('JGLOBAL_DISPLAY_NUM'); ?>
</label>
<?php echo $this->pagination->getLimitBox(); ?>
</div>
<p class="counter">
<?php echo $this->pagination->getPagesCounter(); ?>
</p>
<?php endif; ?>
</form>
mmm yea I can see what you mean. The template does have some issues. And that is not only your problem there are many places were you need to edit your stylesheet. But it's very hard to eyeball all of them and wrap all the solutions in one answer.
But as an advice you can use firebug if you are using firefox or google developer tools by pressing ctrl shift j to open them. You can edit some of your content live and see the changes that are needed to be done in specific places and then you just do them.
For example I found at the section CONTACT the upper right banner has it title popping out of the template. The fix is located in /templates/as002035/css/tmpl.custom.css line 11 by setting the padding to 0 0 20px.
When Creating an account a modal box splashes into my face. You need to fix that by editing the width and the height of that window again by using those tools.
Finally i cant see the logout button " form " since I can't register to your website due to the mail that was not sent in my e-mails. So probably you need a developer to fix all of these things.
I hope I helped a bit.
Besides the (good) advice already provided, there is a missing answer to your question: where does the HTML markup come from?
You will find it in one of two places: first check your template overrides (which I think is the case looking at your question), which would be located in
/templates/as002035/html/com_users/login/default_logout.php (logout component)
/templates/as002035/html/mod_login/ (login|logout module)
if they are not present, then the default Joomla layouts are in
/components/com_users/views/...
/modules/mod_login/tmpl
Added after clarification below, this is the answer the the comments.
you're missing a class "button" so the line of the module should be:
<input type="submit" value="Log out" class="button btn btn-primary" name="Submit">
instead of
<input type="submit" value="Log out" class="btn btn-primary" name="Submit">
(see the added "button"?). Did you find the template ? is it in the overrides? if you can just make that change you'll get the module fixed. As for the component logout form, http://www.guhlmotors.com/index.php?option=com_users
<button class="button btn" type="submit">Log out</button>
instead of
<button class="button" type="submit">Log out</button>

Performs form action even out of the form

Hi having a problem with this code even if i clicked on cancel it will still proceed to use the action of my form even though the CANCEL button is not part of the form, Would appreciate any help.
Here is the code.
<form method="post" action="input_enroll.php" >
<div id="overlay1">
<div>
<h1> Enter Educational Level Entry</h1>
<input type="text" name="level" >
<input type="submit" value="Proceed To Enroll" '>
</form>
<input type="submit" value="Cancel" onclick='overlay()'>
</div>
</div>
EDIT: Any suggestions what would be a better idea? I'm thinking putting the cancel outside the div.
You are having form started, then divs started, then form closed..start form after divs..
as your markup is not correct, browsers will change it as thier parser suggest,
In chrome </form> tag is postponed after </div>s..
<div id="overlay1">
<div>
<form method="post" action="input_enroll.php" >
<h1> Enter Educational Level Entry</h1>
<input type="text" name="level" />
<input type="submit" value="Proceed To Enroll" />
</form>
<input type="submit" value="Cancel" onclick='overlay()' />
</div>
</div>

Categories