I'm facing this strange issue.
I need to upload multiple image with one input. On the input I have a js code that shows me the uploaded image, but when I try to check the $_POST array the image are not submitted.
Half an hour ago it worked well, so I thought it was a cache problem, but even if I empty the cache I cant manage the problem. I cant remember if I changed something, but the code seems to be the same as before (when the code worked).
I work with MAMP on windows 10.
Here is the html (the "form-question" div including the image input is the last one below):
<form action="?mode=dati" method="post" id="dati" enctype="multipart/form-data">
<div class="form-question">
<label for="n2">Nome dell'azienda</label>
<input type="text" id="n2" name="nomeAzienda" value="<?php echo $_SESSION['nomeAzienda']?>">
</div>
<div class="form-question">
<label for="n3">Indirizzo</label>
<input type="text" id="n3" name="indirizzo" value="<?php echo $_SESSION['indirizzo']?>">
</div>
<div class="flex">
<label for="n3">Cap</label>
<input type="text" id="n3" name="cap" value="<?php echo $_SESSION['cap']?>">
<label for="n4">Città</label>
<input type="text" id="n4"name="citta" value="<?php echo $_SESSION['citta']?>">
<label for="n5">Provincia</label>
<input type="text" id="n5" name="provincia" value="<?php echo $_SESSION['provincia']?>">
<label for="n6">P.IVA</label>
<input type="text" id="n6" name="partitaIva" value="<?php echo $_SESSION['partitaIva']?>">
</div>
<div class="form-question">
<label for="n7">Indirizzo email</label>
<input type="text" name="email" id="n7" value="<?php echo $_SESSION['email']?>">
</div>
<div class="form-question">
<label for="immagine">Immagine</label>
<input type="file" name="immagine[]" class="form-control"
oninput="immagine_preview.src=window.URL.createObjectURL(this.files[0]);
immagine_preview1.src=window.URL.createObjectURL(this.files[1]);
immagine_preview2.src=window.URL.createObjectURL(this.files[2]); " multiple/>
<img id="immagine_preview" width="100px" height="100px">
<img id="immagine_preview1" width="100px" height="100px">
<img id="immagine_preview2" width="100px" height="100px">
</div>
<div class="button-wrapper">
<button type="submit" id="registra">Registra i dati</button>
<button type="button" id="prosegui" class="disabled">Prosegui</button>
</div>
</form>
And here is the php:
if ( $_GET ) {
if ( isset( $_GET[ 'id_sondaggio' ] ) || isset( $_GET[ 'mode' ] ) ) {
$id_sondaggio = $_GET[ 'id_sondaggio' ];
$mode = $_GET[ 'mode' ];
}
}
if ( $mode == 'dati' ) {
var_dump($_POST);
die();
}
I'm not getting what's wrong here. Thank you for all your help.
Related
I am creating a specialized WordPress plugin, and its not for use outside of this singular case for the rest of the question we will refer to the wordpress plugin folder as plug-folder. Inside the plug-folder I have multiple files, a file named form_submit.php and a file named form_template.php. form_template.php is registered as a page template that can be applied to any post or page through the WordPress dashboard. The issue is because the form_submit.php file is inside the plugin folder how do I map my form action to post the data to the file? Simply listing it as
<form action="form_submit.php" method="post" >
Will not work as I need because it will be looking for the form_submit.php in the root directory of the site not the plugin folder and trying to map out the URL scheme for it in the plugin folder like
<form action="wp-content/plugins/plug-folder/form_submit.php" method="post" >
Doesn't work either, does a method exist that I am not thinking of?
Edit: After switching to use plugins_url() as suggested its working in one of the two instances where I am using forms. My register form (attached below) is not working, comes back error loading page.
<form action="<?php echo plugins_url( 'register_submit.php', __FILE__ ); ?>" method="post" autocomplete="off">
<?php if($_GET['error'] == 'username'){ ?>
<div class="error_message">
Uh oh! That username is already taken.
</div>
<?php }else if($_GET['error'] == 'email'){ ?>
<div class="error_message">
Uh oh! That email is already in use.
</div>
<?php }else if($_GET['error'] == 'email_invalid'){ ?>
<div class="error_message">
Uh oh! Make sure to enter a valid email.
</div>
<?php }else if($_GET['error'] == 'signup_blank'){ ?>
<div class="error_message">
Uh oh! Make sure to fill in all the fields.
</div>
<?php } ?>
<input type="text" name="first_name" class="signup_input" id="first_name_input" placeholder="First Name" value="<?= $_GET['first_name']; ?>" required>
<input type="text" name="last_name" class="signup_input" id="last_name_input" placeholder="Last Name" value="<?= $_GET['last_name']; ?>" required>
<input type="text" name="email" class="signup_input" placeholder="Email" value="<?= $_GET['email']; ?>" required>
<input type="password" name="password" class="signup_input" placeholder="Password" required>
<input type="radio" name="gender" value="Female" required> <font color="#FFF">Female</font>
<input type="radio" name="gender" value="Male" required> <font color="#FFF">Male </font>
<input type="submit" name="submit" class="btn btn-default" value="Sign Up" style="margin-left: 15px;">
</form>
But my login form works.
<form action="<?php echo plugins_url( 'login_submit.php', __FILE__ ); ?>" method="post" autocomplete="off">
<div class="list-block">
<ul>
<span class="ti-user"></span>
<div class="item-input">
<input type="text" name="email" placeholder="E-Mail">
</div>
<div class="item-content margin-top-15">
<span class="ti-lock"></span>
<div class="item-input">
<input type="password" name="password" placeholder="Password">
</div>
</ul>
</div>
<div class="log-in-btn margin-top-15 margin-bottom-30" >
<input type="submit" name="submit" class="btn btn-default">
</div>
</form>
I am confused as to what the difference is that would cause this.
Use plugins_url()
<form action="<?php echo plugins_url( 'form_submit.php', __FILE__ ); ?>" method="post" >
Codex Reference https://codex.wordpress.org/Function_Reference/plugins_url.
Edit: Please check in wordpress settings. I think you do not have registration enabled.
Hope it helps.
In my custom Wordpress theme, I have custom login form:
<form method="post" action="<?php bloginfo('url') ?>/wp-login.php" name="login">
<div class="login-form-container resp-hidden">
<div class="login-form-container-inner">
<h3 class="form-title"><?php echo __('Login', 'louise'); ?></h3>
<label for="user_login">
<?php echo __('User name or e-mail', 'louise'); ?>: </label>
<input class="para-content" type="text" name="log" placeholder="" value="<?php echo esc_attr(stripslashes($user_login, $user_email)); ?>" size="20" id="user_login" tabindex="11" required>
<label for="user_pass">
<?php echo __('Password', 'louise'); ?>: </label>
<input class="para-content" type="password" name="pwd" value="" size="20" id="user_pass" tabindex="12" required/>
<label for="rememberme"> </label>
<div class="buttons">
<?php do_action('login_form'); ?>
<input type="submit" name="user-submit" value="<?php echo __('Log in', 'louise'); ?>" tabindex="14" class="signupbtn" />
<input type="hidden" name="redirect_to" value="<?php echo icl_get_home_url() ; ?>" />
<input type="hidden" name="user-cookie" value="1" />
</div>
</div>
</div>
</form>
It gets the job done, but problem appears when I am trying to log in from different than default language. Login redirects to the front-page leaving with inactive URL: http://test.com/?lang=en/wp-login.php I am using WPML plugin for two languages, default one is lt_LT and en_US as additional.
I was digging threw all the weekend, but found no valid solution. To make it clear, I don't get if I have to translate core WP wp-login.php page, o is there a shortcut to bypass wp-login.php and redirect user straight to home page?
Many thanks for all possible help and suggestions.
Looking forward,
First change the form action to
<?php echo $_SERVER['REQUEST_URI']; ?>
and use this PHP after the form
if (isset($_POST['user-submit'])) {
login_auth($_POST['log'], $_POST['pwd']);
}
and add this function to functions.php
function login_auth( $username, $password ) {
global $user;
$current_cookie = esc_attr( $_COOKIE['_icl_current_language'] );
$url = '/'.$current_cookie;
$login_page = site_url($url);
$creds = array();
$creds['user_login'] = $username;
$creds['user_password'] = $password;
$creds['remember'] = true;
$user = wp_signon( $creds, false );
if ( is_wp_error($user) ) {
echo $user->get_error_message();
}
if ( !is_wp_error($user) ) {
wp_redirect($login_page);
}
}
After all, here is my solution that worked in my case. Seems, that the problem was language parameter set by WPML plugin. It is possible to check if current link has ?lang=en/ and change it with default wp-login url.
<?php
if($login = strstr($_SERVER['REQUEST_URI'], "?lang=en")) {
$login = wp_login_url();
} else {
$login = wp_login_url();
}?>
<form method="post" action="<?php echo $login?>"
<div class="login-form-container resp-hidden">
<div class="login-form-container-inner">
<h3 class="form-title"><?php echo __('Login', 'louise'); ?></h3>
<label for="user_login">
<?php echo __('User name or e-mail', 'louise'); ?>: </label>
<input class="para-content" type="text" name="log" placeholder="" value="<?php echo esc_attr(stripslashes($user_login || $user_email)); ?>" size="20" id="user_login" tabindex="11" required>
<label for="user_pass">
<?php echo __('Password', 'louise'); ?>: </label>
<input class="para-content" type="password" name="pwd" value="" size="20" id="user_pass" tabindex="12" required/>
<label for="rememberme"> </label>
<div class="buttons">
<?php do_action('login_form'); ?>
<input type="submit" name="user-submit" value="<?php echo __('Log in', 'louise'); ?>" tabindex="14" class="signupbtn" />
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" />
<input type="hidden" name="user-cookie" value="1" />
</div>
</div>
</div>
</form>
i want to get value of input of my form via $_post in my insert page but my problem is that i get error massage:undefined index:track_code and i cant get value of it.the names is same what is problem?
this is my problem why stackoverflow want more detail. this is all detail
<form action="insert.php" method="post">
<input name="track_code" type="text" class="tiny-size" value="<?php echo $track_code_rnd ; ?>" style="width: auto;height: auto" disabled />
</form>
<form action="insert.php" method="post" class="form-horizontal form-checkout">
<div class="control-group">
<label class="control-label" for="firstName">نام<span class="red-clr bold">*</span></label>
<div class="controls">
<input name="first_name" type="text" id="firstName" class="span4" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="lastName">نام خانوادگی<span class="red-clr bold">*</span></label>
<div class="controls">
<input name="last_name" type="text" id="lastName" class="span4">
</div>
</div>
<input name="submit" type="submit" class="btn btn-success" value="خرید" style="width: 66px"/>
</form>
<form action="insert.php" method="post">
<input name="track_code" type="text" class="tiny-size" value="<?php echo $track_code_rnd ; ?>" style="width: auto;height: auto" disabled />
</form>
<?php
$track_code = $_POST['track_code'];
?>
Set this one code in your form
<form action="insert.php" method="post">
<input name="track_code" type="text" class="tiny-size" value="<?php echo ($track_code_rnd)?$track_code_rnd:'';?>" style="width: auto;height: auto" disabled />
</form>
Remove disable tag from your input code. Disable controls wont be posted on server. for that you can make it readonly or make it hide
Try Putting the PHP code on the form. as given below.
<?php
if (isset($_POST['submit'])) {
$track_code = $_POST['track_code'];
}
?>
<form action="your_page.php" method="post">
<input name="track_code" type="text" class="tiny-size" value="<?php echo $track_code_rnd; ?>" style="width: auto;height: auto" readonly />
<input name="submit" type="submit" />
</form>
It will execute the whole file as PHP. The first time you open it, $_POST['submit'] won't be set because the form has not been sent. Once you click on the submit button, it will print the information.
Disabled controls never post on server. So make it readonly or hidden.
I want to keep the data in a text box after submit and inserted into db.
even if i refresh the page data should not change or empty
here is my code
<tr class="form-field1">
<th valign="top" scope="row">
<label for="approved_admin"><?php _e('Collaboration Admin', 'custom_table_example')?></label>
</th>
<td>
<input id="approved_admin" name="approved_admin" type="email" value="<?php echo esc_attr($item['approved_admin'])?>"size="50" class="code" placeholder="<?php _e('Admin Email', 'custom_table_example')?>" required>
</td>
</tr>
if i do this data will be there if i reload empty text box will be shown.I need to make this readonly and onload same text should be there.
Form
<form id="form" method="POST">
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce(basename(__FILE__))?>"/>
<?php /* NOTICE: here we storing id to determine will be item added or updated */ ?>
<input type="hidden" name="sid" value="<?php echo $item['sid'] ?>"/>
<div class="metabox-holder" id="poststuff">
<div id="post-body">
<div id="post-body-content">
<?php /* And here we call our custom meta box */ ?>
<?php do_meta_boxes('Settings', 'normal', $item); ?>
<input type="submit" value="<?php _e('Save', 'custom_table_example')?>" id="submit" class="button-primary" name="submit" / >
<input type="submit" value="<?php _e('Edit', '')?>" id="edit" class="button-primary" name="edit" / >
</div>
</div>
</div>
</form>
I tried doing
<input type="email" name="approved_admin" value="<?php if (isset($_POST['approved_admin'])) { echo $_POST['approved_admin']; } ?>">
and also
<input type="text" name="country" value="Norway" <?php isset($approved_admin) ? echo 'readonly' : ''; ?> >
You can save data after page reload a lot of ways like... Session , cookie, get , post. After this value get by isset and echo .
In your case Post method used..
Try this working fine all thing
<input type="text" name="country" value=" <?php echo isset($_POST['country']) ? $_POST['country'] : ''; ?>" <?php echo isset($_POST['country']) ? 'readonly' : ''; ?> >
You just put field name in isset();
You can use this syntax. Have a try for this.
<input type="text" id="to_date" name="to_date" class="form-control" placeholder="Enter End Date" value="<?php echo isset($_POST['to_date']) ? $_POST['to_date'] : '' ?>" />
The name of the input type has to be mentioned in the isset() condition.
Hi there. Can anyone please tell me how to arrange the list of checkboxes of cuisines label which is retrieved from the data base and when it is displaying it is not in the order coming side by side all together I want it to be displayed in a 3 by 3 format. Here is the code for that:
<div id="frmform">
<form name="frmrestaurant" id="frmrestaurant" method="post" onsubmit="" enctype="multipart/form-data">
<p class="msgsignup">Add Restaurant</p>
<div id="iderror"></div>
<div class="topinputs">
<div> <label for="restaurant_name" class="name">Restaurant Name :</label><input type="text" name="restaurant_name" size="32" id="restaurant_name" value="<?php echo $row->restaurant_name; ?>" class="validate[required,custom[onlyLetter],length[0,100]] text-input" /> </div>
</div>
<div> <label for="website" class="name">Website :</label><input size="32" type="text" name="website" id="website" value="<?php echo $row->website; ?>" class="validate[required,length[0,100]] text-input" /> </div>
<div> <label for="budget" class="name">Budget :</label>
<?php echo $this->lists['budget'];?>
</div>
<div> <label for="idcuisine" class="cuisine" >Cuisine:</label>
<?php echo $this->lists['cuisine'] ;?>
<div> <label for="idcategory" class="category">Category:</label>
<?php echo $this->lists['category'];?>
</div>
The lists of cuisine and category is not displaying properly.
Thanks.
It could be done with php right logic
<tr>
<?php
while($ofetch=$db->fetchNextObject($query))
{
$j++;
?>
<td width="33%">
<input type="checkbox" name="service[]" id="service" value="<?php echo $ofetch->service_id?>" /> some text
</td>
<?php if($j%3==0) { echo "</tr><tr>";}
}
?>
</tr>