我需要以提交的表单发送字段的电子邮件通知。
我的问题如下:表格中的HTML选择标记。
<select id="country_code" name="country_code">
<option value="" selected disabled>Country</option>
<option value="AR">Argentina</option>
<option value="BR">Brazil</option>
<option value="CG">Congo</option>
<option value="ZW">Zimbabwe</option>
</select>
下面我会看到所选选项的国家/地区代码:
$country_code = $_POST["country_code"];
如何在选项标签(即国家/地区名称)中使用PHP所选值的文本?
注意: 我无法使用MySQL或JavaScript,也无法更改选择框值。
答案 0 :(得分:1)
HTML:
#!/bin/bash -x
# Version: ImageMagick 6.9.6-7 Q16 x86_64 2016-12-05, running on macOSX 10.11.6 El Capitan
# run the script in bash terminal like so:
# ./my_script.sh date1 date2 "employer" "position" "path to logo img"
# remember to chmod the file to be able to run it: chmod +x my_script.sh
# this script is partially debugged with http://www.shellcheck.net/
args=("$@")
echo
echo date1 = "${args[0]}"
echo date2 = "${args[1]}"
echo employer = "${args[2]}"
echo position = "${args[3]}"
echo logo_path = "${args[4]}"
custpath=($HOME/Dropbox/+\ B-folder/A\ Folder/Gfx/Logos/)
echo custpath = "${custpath[@]}"
date1=${args[0]}
date2=${args[1]}
employer=${args[2]}
position=${args[3]}
logo_path=${args[4]}
# find the folder in the logo path
# see this article for how to replace a pattern from the end
# http://www.thegeekstuff.com/2010/07/bash-string-manipulation/
folder_path=${logo_path/%\/*//}
echo folder_path = $folder_path
output_dir="${employer} - ${position}"
echo output_dir = $output_dir
echo
convert \( -draw 'circle 108.5,101.5 159.5,160' -stroke "rgb(241,142,0)" -fill "rgb(241,142,0)" -size 1022x798 canvas:white -bordercolor black -border 1x1 -fill black -stroke black -draw 'rectangle 1,721 1022,798' -fill white -stroke none -background none -gravity south -page +93-11.5 -font /Library/Fonts/RobotoCondensed-Light.ttf -pointsize 35.5 label:'A Logo' -flatten \) $HOME/Dropbox/+dev/coding_images/imagemagick/a-logo-neg.png -geometry 207x+386+6.5 -composite miff:canvas0
convert -size 125x150 -background none -gravity center -stroke none -fill white -interline-spacing -7 -pointsize 33 -font /Library/Fonts/Roboto-Bold.ttf label:"Last\ndate\n${date1}/${date2}" miff:- |
composite -gravity center -geometry -402-300 - canvas0 miff:- |
convert - -size 255x150 -background none -gravity west -stroke none -fill black -kerning 0.5 -font /Library/Fonts/RobotoCondensed-Regular.ttf label:"${employer}" -geometry +33-102 -composite miff:- |
convert - -size 486x320 -background none -gravity west -stroke none -fill black -kerning 0.25 -interline-spacing -5 -font /Library/Fonts/Roboto-Regular.ttf caption:"${position}" -geometry +32+87 -composite miff:- |
# convert - $HOME/Dropbox/+\ B-folder/A\ Folder/Gfx/Logos/$logo_path -gravity center -geometry 350x350+280+70 -composite -set filename:dimensions '%wx%h' "$HOME/Dropbox/+\ B-folder/A\ Folder/Gfx/Logos/${folder_path}LN-${employer}-${position}-${date1}_${date2}-%[filename:dimensions].png"
# mkdir -pv -m u=rwx "$output_dir"
# [ -d "$output_dir" ] && echo "Output Directory Exists" || mkdir -pv -m u=rwx "$output_dir"
# cd "$output_dir"
# below is the final version of the output path I want to have, if only the $custpath variable worked
# convert - $logo_path -gravity center -geometry 350x350+280+70 -composite -set
# filename:dimensions '%wx%h'
# "${custpath}/${folder_path}/${output_dir}/LN-${employer}-${position}-%[filename:dimensions].png"
convert - $HOME/Dropbox/+\ B-folder/A\ Folder/Gfx/Logos/"$logo_path" -gravity center -geometry 350x350+280+70 -composite -set filename:dimensions '%wx%h' $HOME/Dropbox/+\ B-folder/A\ Folder/Gfx/Logos/"$folder_path"LN-"${employer}"-"${position}"-"${date1}"_"${date2}"-'%[filename:dimensions]'.png
convert - $"{custpath[@]}"/"$logo_path" -gravity center -geometry 350x350+280+70 -composite -set filename:dimensions '%wx%h' $HOME/Dropbox/+\ B-folder/A\ Folder/Gfx/Logos/"$folder_path"LN-"${employer}"-"${position}"-"${date1}"_"${date2}"-'%[filename:dimensions]'.png
rm canvas0
# open $HOME/Dropbox/+\ B-folder/A\ Folder/Gfx/Logos/"$folder_path"LN-"${employer}"-"${position}"-"${date1}"_"${date2}"-%[filename:dimensions].png
open $HOME/Dropbox/+\ B-folder/A\ Folder/Gfx/Logos/"$folder_path"LN-"${employer}"-"${position}"-"${date1}"_"${date2}"-*.png
# remove output file when testing the result, remove this line when script is finished
# sleep 5
# rm LN-"${employer}"-"${position}"-"${date1}"_"${date2}"-*.png
PHP:
<select id="country_code" name="country_code">
<option value="" selected disabled>Country</option>
<option value="AR">Argentina</option>
<option value="BR">Brazil</option>
<option value="CG">Congo</option>
<option value="ZW">Zimbabwe</option>
</select>
答案 1 :(得分:1)
提交表单时更改JS中的值 要么 将值更改为:
<option value="CG_Congo">Congo</option>
然后使用explode或split
拆分它$location = explode("_", $_POST["country_code"]);
或将其保存在数据库中并查询OR 使用以下翻译在代码中保存数组:
$translations = ['CG' => "Congo", etc];
然而,真的不会推荐最后一个。 我不明白为什么你不会改变选项价值,因为你仍然得到国家代码,但国家名称是一个补充。
编辑:在线找到JSON国家/地区名称列表:http://country.io/names.json, 你可以这样做:
$country_code_to_name = json_decode(file_get_contents("http://country.io/names.json"), true);
echo $country_code_to_name[$_POST["country_code"]];